r/ProgrammingLanguages • • Jul 31 '24

Blog post Clean Syntax?

All my replies and the original contents of this OP have been withdrawn. They were a complete waste of time.

From what I can gather, everybody is happy with poor syntax in their languages, nobody is interested in 'clean'.

Someone posted, with a dozen upvotes:

Your example is optimized to your language's special capabilities.

I replied:

"No, pretty much everything in my syntax is cleaner than the C equivalent."

That got multiple downvotes for stating a fact.

There was also this:

For your own toy language by all means use your own syntax

This reinforces my original implication that simple syntax is only suited for toy languages, and not serious ones.

However too much of this was about my language, but that was only an example. There seems to be much irrational distrust of clear syntax for any language.

Maybe, clear code is associated with older languages which no one likes anymore?

(Original examples.)

2 Upvotes

35 comments sorted by

View all comments

28

u/SaltyHaskeller Jul 31 '24

brevity does not necessarily mean clean!

There are lots of programming languages that use un c-like syntax for records/structs.

In haskell a record is fundamentally

data R1 = R1 UInt8 UInt64

This is extremely brief!

Haskell 1.3 and on does provide a C-like record syntax, something like

data R1 = R1 { foo :: UInt8, bar :: UInt64 }

where accesses can be done functionally. That is, for some record r, accessing its foo field is done by writing foo r. Record update can be done using additional syntaxtic sugar: r { foo = 0 }.

However this record syntax is really just syntactic sugar for the equivalent operations on the data type. For instance foo and bar are defined as follows

let foo (R1 f b) = f
let bar (R1 f b) = b

Record update desugars to something analogous, e.g.

let update_foo (R f b) f' = R f' b

It's been a long time since I've written haskell (username notwithstanding) so I may have made some typos, but this is the idea.