The Search for an Elegant Programming Language

in #ysrv2 years ago

Crocus are the first flowers that appear in our garden. They signify the melting of the Winter snow and the coming of Spring.

Computer Programming and the Liberal Arts

Last summer I wrote a series of articles on Proof of Brain #POB that touched on the history of the classical liberal tradition. This tradition stretches back to the writings of Aristotle, Cicero and other philosophers of the ancient world.

The heart of this approach to learning is a collection of subjects called "The Trivium."

The three legs of the Trivium are "Grammar," "Logic" and "Rhetoric."

Grammar refers to the structure of language. Logic refers to the structure of ideas and rhetoric to the art of communication.

It seems to me that the study of computer science maps well to Trivium.

Computer languages present grammatical structures that interface with computers. Compilers translate the computer languages into structures the computer can execute.

Just as rhetoric is the art of communication, computer programming is the art of instructing computers to do useful things.

A computer language is simply a collection of grammatical structures that help programmers interface with computers.

An Overemphasis on Grammar

I've been dissatisfied with most of the computer languages that I've encountered through the years.

What seems to happen is that designers of computer languages have a tendency to fall in love with the grammar of the program. This causes programmers to focus on the grammar of the computer language and not on the logic run by the machine.

IMHO, programming languages should be designed to clarify the logic run by the machine.

Most languages are a mixed bag of tricks.

I've been reading the manuals for Rust. Rust does several things that I like. For example, Rust focuses attention on the difference between the Stack and the Heap.

The Stack and Heap refer to two types of memory accessible to a computer.

The stack is an extremely fast construct that contains fixed length data.

The heap holds variable length data. Programs uses pointers on the stack to track data on the heap.

In functional programs, the stack is organized in cleanly structured layers. A layer of code will add data to the stack. After executing the code, the program automatically removes the data from the stack.

A strongly typed language that takes full advantage of the stack and that uses the heap sparingly will be faster than one that overloads the heap.

One of the big advantages that functional programs have over object oriented programs is that functional programs do a better job managing the stack.

Things I like About Rust

Another thing that I like about Rust is that, since it was designed as the base of a web browser, it has robust features for handling multibyte UNICODE and UTF8 characters. C was designed around single byte ASCII and ANSI character sets which fail when confronted with multibyte characters.

Since Rust was designed for a web browser, the standard libary includes a robust HTTP Listener.

C programs often interface at the socket layer. I've heard many nightmares of people who messed up their socket program.

I guess I could retell a stupid story. I worked for a company that lost $11,000 because the university trained programmer we hired to write the credit card interface had a glitch in the object he used to manage the socket used to process credit cards.

His socket program would occasionally charge the current customer's purchase to the previous customer's credit card.

It was a total nightmare.

The company almost lost its ability to access the credit card network because of the mistake.

I ended up writing my own credit card server. For those who care, I replaced the state of the art credit card object with a big-ass legacy procedure because, in my untutored opinion, charging the bill to the wrong customer is the absolute worst mistake that a credit card processor can ever make.

My credit card processor was really quite interesting in that it encyrpted the credit card numbers. I used a secure function to decrypt the credit cards; So only the people who had access to the decryption program could ever see the credit card number. The decryption program would record each credit card use.

Now for My Complaints about Rust

Rust uses terse grammatical structures to force programmers to use the Rust style of coding.

While I recognized that clever grammatical structures can improve a program. For example it is common to use the "&" to distinguish between a character and a pointer, Rust seems to have too many little grammatical trick.

For example, removing the ";" from the end of the line turns a statement into an expression. The bang symbol turns an program into a macro. There are tons of weird operators like ::, a "b" before variables. They have a large number of weird operatives like "<'_>" and "<T>" that you have to remember.

The language makes excessive use of self references and makes regular use of numerous unintuitive methods. Here is a typical call:

let contents = fs::read_to_string(filename).unwrap();

It it not intuitively obvious what ".unwrap()" does. Apparentely .unwrap() is defined in a module called "prelude." But there appears to be different prelude modules.

Rust and a Techtosterone

I have a pet theory about technology. I suspect that there is a hormone in play called "testosterone" that attracts certain people to geeky looking computer code.

We all want to feel special. I suspect that some people feel a rush of this testosterone hormone when they see geeky symbols in code. Such people would find a long string of code seperated by random dots, dashes and colons exciting.

I keep coming across strange Rust code like this.

#[macro_export]
macro_rules! vec {
    ( $( $x:expr ),* ) => {
        {
            let mut temp_vec = Vec::new();
            $(
                temp_vec.push($x);
            )*
            temp_vec
        }
    };
}

The operations of the code is not intuitive. There are weird dollar signs, asterisks, pounds and bangs in strange places.

Anyway, I have my web listener up and running and have been testing it.

I don't want to write about my experience with Rust because, to be honest, I find the vast majority of Rust code to be hideous.

Rustaceans (that's the name for people who like Rust) have high levels of techtosterone.

My fault is that I favor elegance and clarity. To be honest, must of the code I've encountered in studying the Rust language makes me feel physicall sick.

I still like the robust TCP listener along with the strongly typed variables and the attention that Rust pays to the stack and heap.

Conclusion

My post started with a discussion of classical grammar and logic.

The term grammar refers to the structure of language. Logic refers to the structure of ideas. In world of computer programming, the term logic refers to the actual operations run by the machine.

I judge computer languages by how well the language elucidates the actual operations of the machine.

While I like the direction Rust is taking with functional program, it seems to me that Rust has far too many little grammatical tricks for my taste. My guess is that the designers of the program fell in love with their esoteric grammar.

I can make Rust do what I want, but if I can't find a way to make the program elegant, I might give up on this experiment.

I am seriously thinking of giving up and Rust and writing my project in C.

And, yes, I can't believe that I just said that I am thinking of writing in C because it is more elegant than Rust.

I've worked on projects that failed because of bad socket programming done in C. I've worked on projects that failed because the architect of the program developed a bad object model for the project.

Of course, I was not the one doing the socket programming and i would not use an object model for a web server.

About the Picture

Hocus pocus here's a crocus! I snapped the picture below yesterday. I snapped the picture at the top of the page just before penning this article.

Sort:  

I really like to meet a fellow programmer on hive really , I never learned rust but I can ways recommend Golang programming languages

Dies crocus ptoduce saffron and this plant is good for calming pain and make medicine

Interesting idea.

Commercial grade saffron comes from Crocus sativus which flowers in the Autumn and is purple. I will check out the stamens on these yellow plants.

A Yellow Crocus is most certainly PIMPED ~ The first sign of Spring !

!PIMP


You must be killin' it out here!
@andy-vibes just slapped you with 5.000 PIMP, @yintercept.
You earned 5.000 PIMP for the strong hand.
You can still slap 2/3 more people today.

pimp_logo


Read about some PIMP Shit or Look for the PIMP District