Conversation
my ideal programming language philosophy (long)
Show content

in the past I’ve posted about how my ideal language would be made out of the bare minimum of simple parts, and then built out from there as a tree structure of abstractions

the root node would unfortunately have to be defined in natural languages which are messy and imprecise, but all of the root’s child nodes would be defined in terms of the language features in the root node - as well as having natural language descriptions to help people understand what they’re reading and why it’s designed that way

and for every node in the graph, its features would be defined only in terms of the features contained in its child nodes (with natural language to help explain things more of course). also, each child node would reuse as many concepts as possible from its parent nodes, to minimize the number of special cases that a user of the language would have to learn

there are a few reasons why I want a language like this:

  • just simple aesthetics. it’s beautiful to me to take the bare minimum of parts and build outward from that, and I love that if some node somewhere in the tree isn’t beautiful for someone, then they can make their own node instead
  • more importantly, beginners can learn in discrete “steps” and gain a basic understanding very very quickly. after they’ve learned the root node they can feel accomplished that they’re able to do everything the language is capable of already, and all there is left to learn are bonus convenience features
  • as they learn more and more distant nodes, they’re able to incrementally increase their ability to express complex thoughts using the language - effectively allowing them to learn chunking in the new language
  • every single feature of the language, not including the root node, is defined with complete precision because it’s written in code rather than natural language
  • in theory, a language designed like this would require users to learn the minimum number of discrete concepts in order to use the language - which would also create a “there’s only one way to do it” effect where users can often correctly guess how to use a new language feature just by applying existing language features in the way that makes the most sense

I feel like a lot of languages over-rely on people “just knowing” what different behaviors are and do, and they also take for granted that users of those languages are willing to memorize arbitrarily many special cases that could have been simplified by reusing existing concepts. just compare Lua’s import system with any other scripting language’s import system for a great example. Lua’s import system only has two special-case rules (how it finds the file, and the fact that that file gets executed like a function) and otherwise works entirely using pre-existing language features. can any other language say the same? if so I want to know about it

meanwhile Python is a mess of “okay so… this directory is treated like a module, right? is that in the search path? wait this is from . import foo so it looks in the current directory… but what’s ‘the current directory’ in this case? wait no it’s not the current directory it’s the current module, isn’t it? but how does Python define a ‘module’ again?” I’ve used Python since I was 14 and I still couldn’t tell you the behavior of a lot of imports without running it just to make sure. and my experience is that every programming language besides Lua is like this. so I’m forced to experiment with each import system by trial-and-error instead of just understanding it right away in terms of stuff I already know

and I think that’s a microcosm of a bigger problem, which is that languages take for granted that their users are willing to learn arbitrarily many special cases, extra syntax rules, new keywords, etc. a lot of languages are really fucking big and every new feature is a self-contained “thing” that has to be learned in complete isolation from anything else in the language - without any familiar reference point to understand it from (looking at you, Rust)

but imagine, instead, if I had a clear progression of nodes to traverse, and traversing those nodes required me to learn as few discrete concepts as possible - but rather let me recycle my old knowledge to learn each new system. wouldn’t that be so much better - not just for learning, but for understanding and applying that knowledge?

anyway, I’ve been hopeful that there’s some Lisp language out there that could do this for me. since they can be built up from literally like 9 discrete concepts, and from there it’s possible to build an arbitrarily complex language, with special syntax and built-in DSLs and everyting - which I find incredibly beautiful

unfortunately the Lisps that I’ve found so far (other than Fennel) have felt… not good. and they definitely don’t follow this philosophy. so I’m still looking for my ideal language, or at least something a bit closer to it than Lua is, in case it’s out there somewhere (currently I’m hopeful about Scheme and warily curious about Haskell)

in the meantime, though, I’m happy to have Lua and Fennel because they get pretty damn close. especially Fennel

1
0
2
re: my ideal programming language philosophy (long)
Show content

here’s an example of what I mean. let’s say that my ideal language is a Lisp (because that seems likely). The root node would have natural language explanations of how to use (cond) and (defmacro) and other language features like that. it would also define what the word “evaluate” means and what a “form” is and etc. but then a child of the root node would contain stuff like:


(if) is defined as:

(defmacro if (condition if-form else-form)
  `(cond ,condition ,if-form
         true ,else-form))

in other words, (if) evaluates to the if-form as long as condition is truthy. otherwise it evaluates to the else-form. either way, only one form is evaluated. here are some examples:

(examples are so fucking important - although I won’t give any here because I’m lazy :P. massive bonus points if the examples are so exhaustive that they’re used as unit-tests for the language)

1
0
2

in general I think that more languages should take “how is someone going to learn this language” as a serious design consideration early on

and I think that it’s not only possible, but a very good idea, for:

  • the documentation of the language
  • a specification for exactly how the language works
  • a tutorial for new users of the language

to all be one unified thing

2
0
3

in a normal language like Python the way things work is that someone says “I would love to use this language, if only it could do [thing]” and then the designers may or may not add that to the language. and over time the language gets more and more complex as new features and syntactic rules and special cases are added

but something that I find incredibly beautiful about Lisps is that that is completely unnecessary. if you want a new language feature in a Lisp language, you can just add it for yourself. users of the language have exactly as much control over what the language does as the actual designers of the language do, and adding new language features isn’t even that hard

0
0
3

@kasdeya the one thing that Python does well (generally, not always) that I will forever love it for is the idea of having 1 optimal way of doing something.

No matter what you're doing there is usually 1 preferred and optimal way of doing it. And in so many other languages I find myself spending precious times debating whether one way or another about pure implementation which is *insane*.

1
0
1

@vapourisation yess omg - I’ve had this exact problem with both Common Lisp and JavaScript and it drives me absolutely crazy. I want a language that gives me as few opportunities to bike-shed as possible lol. and I definitely agree that Python does an amazing job of this. as much as I’m criticizing Python it is actually one of my favorite languages

1
0
1

@kasdeya thank god in not alone! JS is hell for this. There are 5 different ways of doing everything and each being subtly different drives me crazy.

I can't tell if I'm just too much if a n00b but I've come across this in a few other languages as well and I get that as engineers we want freedom, but my god, if there *is* a "best" method of doing something *tell me what it is*!

I feel bad for saying it but Python is also one of my favourites. It's such a simple language but it truly got many simple things right when it comes to making it easy to learn.

0
0
1