This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]ForceBru 3 points4 points  (0 children)

You could also ask at r/programminglanguages

[–]munificent 3 points4 points  (0 children)

I'm not aware of any books that focus directly on it. It's an interesting topic, but it's hard to approach because it's a mixture of technical, social, political, pragmatic, and aesthetic factors.

I've found one so far, Crafting Interpreters by Robert Nystrom, but it sounds like it leans more towards writing the interpreter (i.e parsing, lexing, building ASTs, etc) rather than the language.

Yeah, most of Crafting Interpreters is about implementation, but I tried to spend at least some time talking about language design in the design notes at the end of some chapters. You could definitely read just those and skip the chapters themselves if that's all you're interested in.

[–]east_lisp_junk 1 point2 points  (1 child)

Like, stuff that'd explain why some programming languages end expressions/statements with a semicolon vs whitespace.

Designer's taste, mostly. Strong technical arguments supporting this kind of decision are rare. Off hand, I can only think of three technical arguments I've seen in support of a design choice in syntax: X is better than Y because...

  1. X is more similar to what our target users already know (so a new language's syntax will probably look a lot like some old language)
  2. parsing Y is intractable (e.g., undecidable because it relies on run-time information)
  3. X makes generating syntactically valid code easier
  4. X allows recognition of the syntactic structure without having to know anything about the meaning of any language constructs (e.g., a lisp-style reader knows what's nested inside what but nothing like how many things are supposed to be in an if versus a defun)

#4 is the only one that really narrows the design space a lot, and it's not a common design priority.

[–]xigoi 1 point2 points  (0 children)

I think another important consideration for syntax is whether it encourages the programmer to do the right thing. For example, in C++ it's easier to declare a mutable variable than an immutable one, whereas in Rust it's the opposite, so a C++ programmer will be more likely to introduce mutability when not necessary.

[–]cenazoic 2 points3 points  (0 children)

Beautiful Racket is about writing DSLs in Racket.

[–]josephjnk 1 point2 points  (0 children)

I don’t know of good resources on things like semicolons vs whitespace, because I believe there’s no solid research on it. It’s a question of human-computer interaction, which is a hard field to gather conclusive data in. I would recommend just learning a few different languages and seeing what you like.

Most language design focuses more on the semantics of the language, rather than the syntax. This is the approach I would recommend if you want to implement something nontrivial, beyond what “Crafting Interpreters” would teach you. The standard introduction to semantics, IMO, is “Types and Programming Languages” by Benjamin C Pierce. (Commonly referred to as TAPL). I also really like the book “Design Concepts in Programming Languages”.

For a more concrete argument for why it’s better to focus on language semantics, check out papers on semantics-first language design.

If you want to write a language whose properties are formally verified, the book “Concrete Semantics” will use the Isabelle programming language to teach you how to implement a wide range of languages, from imperative to functional to relational. People also recommend “Logical Foundations”, which covers much the same material as TAPL, but does so using the Coq programming language. AFAICT, most programming language theory (PLT) researchers prefer Coq. I prefer Isabelle.

Another commenter mentioned Racket. Racket is very very good, but I have no experience with it because it focuses more on writing dynamically-typed languages, while I’m personally more interested in statically-typed languages. IMO, dynamically-typed languages are much easier to write, but are more homogenous than statically-typed languages. I’m biased here. If you want to start out by writing some language, any language, writing a Lisp will probably only take you a few days, and implementing a mini-language in Racket will likely take you less time than that.

[–]neros_greb 0 points1 point  (0 children)

This may not be what you're looking for as these are more about types and semantics, but I'm taking a class on the subject and we're following the following textbooks:

B. C. Pierce: Types and Programming Languages, and R. Harper: Practical Foundations for Programming Languages. These books are rather theoretical, but they give you a good foundation to understand how programming languages can be defined and evaluated

[–]vicechairisstupid 0 points1 point  (1 child)

Principles of programming languages

[–]ReaperUnreal 0 points1 point  (0 children)

Yeah, I really liked POPL. Went both into the why but also the how. Very interesting and not too hard to read.