by sitkack · 8y ago · 0 comments
Until end users can construct their own languages, language designers have a long way to go.
Few times, alas. Most of the times it's some over-engineered monstrosity by architecture astronauts or people trying to be clever.
Sometimes I prefer "and then, and then, and then" over "sign up async observer, send through our java-redux, oops forgot to implement async actions, hack in an and then and then and then case into it" -solutions.
Or musicians like Rich Hickey. Without a strong sense of aesthetics you can't build good software, that's where the "over-engineered" stuff comes from. Aesthetics and a sense of proportion makes miracles.
I like code that says "does this, then that, then that etc" (as opposed to Eg. the misuse of the concept of abstraction in Java development). Easy to read, naturally follows into a better mental model of whats going on, which is especially important if you are reading code from somebody else. This is not a test of intelligence, as some programmers may be inclined to think. Its about using what solves the problem - easily, even if it is "this then that" style.
I don't want to come into work and fight to de-tangle the inner minds of a crazed developer. I'd rather come in, and use my brain to add value. (Reading simple clean code, and using my brain to add to it).
Goodness. If we had to learn a language just to be able to consume a fellow engineers mental model, we would all be in trouble.
Just keep the custom language dumb enough and it will be glorious.
Anyway, the majority of the programming community tends to dislike that sort of freedom, preferring maintainability and the ability to work as a team where every team member isn't off creating their own dialect.
The majority of the programming community doesn't use Lisp.
Lisp metaprogramming is very different to metaprogramming in other languages (extreme opposite example: C preprocessor macros). Lisp homoiconicity makes macros easy to write, and easy to maintain.
The majority of the programming community dislikes that sort of freedom, but the overwhelming majority of Lisp programmers considers it an essential freedom.
After all, we're all doing high-level programming. We need tools to abstract stuff, and the more complex the problem is, the more powerful the abstraction features should be.
The state of the art in abstracting stuff in 2018 is still either hindley-milner languages (ML family), Prolog and friends (Erlang), or Lisp (Common Lisp, Scheme).
Oh, and while very unconstrained in some sense, the syntax also strongly "suggests" some sort of applicative model, so call/return again.
So maybe too constrained where it shouldn't be, and too unconstrained where it would need to be more constrained.
1. Dataflow
With the popular variant pipes + filters. There is also synchronous dataflow, which can be compiled to state machines. This has recently been bastardized as "FRP" (distinct from Conal Eliot's original FRP).
What's kind of amusing is that traditional programs typically get translated to dataflow variants twice: first, the compiler turns procedures into a dataflow graph and generates code from that, later most OOO speculative processors turn the computation into more or less a dataflow graph again.
2. Asynchronous messaging
See Erlang/Actor model. You send messages (calls), but they don't return.
3. Implicit invocation/broadcast
You send out messages/broadcasts. Clients can register. There is no 1:1 correspondence between call-sites and receivers. May also be asynchronous (but doesn't have to be).
4. Constraints
Both dataflow constraints (see spreadsheets) and "solver" constraints. You just specify the relations you want to hold.
5. Coroutines
Normal call/return runs the callee to completion. Coroutines interleave. The Floyd paper mentions nested coroutines, which I have to look at.
etc.
A good reference is Software Architecture: Pespectives on an Emerging Discipline by Shaw and Garland
Seriously, I replied to the second part of your comment. Lisp may be the pinnacle of DSL-friendliness, but, as you say, plenty of languages have various measures of metaprogramming support, and yet, as you note, those facilities tend to be universally disliked by the mainstream programming community :).
(I believe that another strong reason for this is that the mainstream programming community is, for better or worse, eternally stuck in the "cater to the newcomers" mode. Effective use of metaprogramming requires a deep understanding of more abstract principles behind programming and complexity management, and are indeed dangerous in hands of beginners.)
http://journal.stuffwithstuff.com/2013/07/18/javascript-isnt...
"Modeled on" <> "is"
Brendan Eich admired Scheme and was still very familiar with SICP at the time. Perhaps "inspired by Scheme" would clear up the misunderstanding?
My question was about creating DSL's in JS. Is it simple enough that people actually do it in professional software development?
If it is, then I call into question the assertion that the majority of the programming community doesn't want to use languages giving them that much freedom.
There are some interesting things people have done with fake operator overloading: http://2ality.com/2011/12/fake-operator-overloading.html
I've not seen a JS DSL attempt that wasn't merely a "toy", but there's probably more room to explore ideas than people give JS credit for. You could also argue that there are plenty of DSLs out there as things like Babel plugins.
A description like
"I went off the platform and then on the train and then I looked at the nearest seat and then I saw it was occupied and then I looked at the next seat and then I saw that was occupied too snd then I repeated that and then I saw an empty seat and then I walked toward it and then I sat down and then ..."
is begging for structure by wrapping up into procedures
"I boarded the train, and then I located the closest free seat, and then I sat down in it ..."
with the obvious definitions. That can in turn can be further improved to
"After boarding the train I sat down in the first free seat ..."
where the relations between the things are more useful than "and then".
I often wish for a more rich way to layout a complex 2-level decision tree. Dividing it up into sub-functions/classes scatters the logic, while putting it all together is too heavy. However a 2D decision table would often be perfect.
A good point of comparison is technical writing. Think back to the best textbooks you read: they didn't have the flourishes and sophistication of literary writing, but they still had a significantly richer structure and organization than, say, a children's book. They needed this richer structure to get their ideas across effectively. You can't write a coherent textbook in the style of Where's Spot?
The same goes for code. You can be too clever, sure, but you can also not be clever enough. On a scale from "Salman Rushdie" to "Clifford the Big Red Dog", you don't want to be at either extreme.
Is this hard? Yes! Writing readable code is a skill unto itself, distinct from writing working code. People don't always agree on what is and isn't readable, but that's true for writing too. Still a worthy goal, just one that doesn't lend itself to simple rules. You just have to build up the right skills from experience.
Not sure what level of clever Salman Rushdie is acceptable for?
Salman Rushdie style is reserved for libraries that make a massive impact. Learning abstractions like that is like learning a new part of the language so it has to really pay off. Rare but not impossible.
The Haskell lens[1] library is a great example. It's almost too clever for its own good and learning it is like learning a new programming language, but it is such an improvement for the entire codebase it's worth it. I use it widely at work and it pays for its own difficulty almost immediately. (It's also important that it can't achieve some of its core functionality without the "clever" things it does.)
The documentation could use a bit of work though :/.
We don't talk about c-groups and compressed files with metadata, we talk about containers and images. We don't talk about individual machines running a number of highly specialized daemons with configuration files, cryptographic keys, and networks-in-networks, we talk about clusters and pods and gateways.
Notwithstanding that much of the code which has built up these sweeping generalizations is built of a tangle of red dogs, the abstractions are very high level and mean we rarely have to discuss infrastructure at a very low level.
Of course, there's a twist to that as well, that hearkens back to an earlier statement: the understanding have been limited to an extremely high level as well. The number of people who can troubleshoot a container cluster is small, and growing smaller. We've intentionally created cliff notes of "Salman Rushdie" novels and believe that's all the populace needs.
I believe the the art of programming is actually writing the code in a way that transitions the reader through context changes keeping the amount of context necessary to understand what's going on to a minimum.
One of the best things about humans is how easy it is for us to work at multiple levels of abstraction simultaneously, as long as we're guided to and between them properly. Good code - hell, good engineering - exploits this to create things which otherwise wouldn't fit in a person's head.
The problem is, the location of the sweet spot depends on the reader (or at least, on their familiarity with the idioms used...)
Great code should be predictable, obvious and easy to change.
Programming is specialized work (I'd call it a discipline, but then we'd have to argue whether it's more an engineering discipline or art discipline). You have to gain knowledge and experience to understand it.
A bridge blueprint is not understandable for all. It is understandable for all who took time and effort to gain education necessary to understand it.
(The motivation between this comment is to counter the increasingly noticeable sentiment in our industry that everything needs to be dumbed down to the lowest common denominator; it's an understandable sentiment if you're selling something and want the biggest market, but it goes against what's needed to build great things.)
Greatness is highly dependent on context. I think your statement on greatness would apply to code that helps you learn and think.
This is, however, NOT the kind of code I'd want to see at work. Great code in a business setting is simple, easy to understand, and has absolutely no subtlety.
If I was looking for a literary example, great code in a business setting would be like the writing style you'd see in a newspaper: written for easy consumption by the greatest number of people possible.
Preferably at 2 AM on a Saturday, when production is down ;)
I jest, but I agree with your statement.
To add to p2t2p's comment, procedural programming doesn't offer very powerful high-level abstractions. OOP on the other hand is so powerful that it's easy to do wrong.