AstonJ

AstonJ

The syntax thread!

:smiling_imp:

What is your preferred syntax style and why?

Perhaps we can add examples and use the code below as a simple reference point (how would you write it in your chosen language?) but feel free to add additional examples if you feel they show off your preferred syntax well too.

Ruby

class Ball
  def initialize(colour)
    @colour = colour
  end

  def red?
    @colour == "red"
  end
end

my_ball = Ball.new("green")
my_ball.red?
# false

Most Liked

davearonson

davearonson

One thing I like about the syntax of typical OO languages, and “pipelined” languages like Elixir, is the concept of “take this, do this with it, then do that with it, then do the other thing with it”. That concept really helped me pick up Elixir pretty quickly after realizing that |> was very much like . just without the implicit matching on whatever kind of thing (Ruby object, Elixir data) you had at that time.

hauleth

hauleth

Whatever people say I prefer languages with block delimiters instead of off-side rule. Off-side rule is okayish in configuration languages and other languages that describe trees (like HAML or Slime), but IMHO do not works well in programming languages (sorry Python, I never really liked you anyway).

Korbin73

Korbin73

Hands down my favorite syntax is ML family of languages ocaml/f#/haskell/Elm

let registerNewUser dbClient =
    request ( fun inputGraph ->
      Newtonsoft.Json.JsonConvert.DeserializeObject<UserRequest>(inputGraph.rawForm |> System.Text.ASCIIEncoding.UTF8.GetString)
      |> hashPassword
      |> registerWithBson dbClient
      |> RealWorld.Convert.userRequestToUser
      |> jsonToString
      |> Successful.OK
    )

Why? Whitespace is a natural idiom in written languages. We use indentation in table of contents, spaces between words, paragraphs, etc. So adding glyphs like brackets or begin…end in a language is completely redundant. In ML family languages all symbols have contextual meaning. Parenthesis are used to group “stuff” together. Brackets are added when the need to indicate a “block” only in certain contexts.

Simply put, if whitespace significance didn’t matter in programming languages, then remove all of the spaces in your C family languages that the compiler is happy to build and see if you like it LOL

That being said, I don’t dislike C-family languages (I program in swift and kotlin on my job) but ML syntax is definately the most pleasant for me to read due to the low visual “noise”.

Popular General Dev topics Top

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1021 17090 374
New
KyleHunter
What is a good language for beginners to make apps like snapchat and instagram?
New
AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
New
axelson
Can anyone recommend a tmux session switcher? I’ve used https://github.com/siadat/session-finder in the past but it’s not very actively m...
New
AstonJ
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face: Perhaps if there’s enough peop...
New
New
jamiedumont
This is all going to be a bit hand-wavey and straight off the top of my head, so bear with me, but it’s a thought/debate that’s been ratt...
New
OvermindDL1
What shell(s) do you use, why do you use them, and how do you have them configured? Note, this is about shell’s, not terminals, terminal...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1139 25472 754
New
malloryerik
With 100% less blockchain. I went searching for a lightweight immutable database that could be audited and ran into this. I guess this ...
New

Other popular topics Top

AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
Exadra37
Please tell us what is your preferred monitor setup for programming(not gaming) and why you have chosen it. Does your monitor have eye p...
New
New
AstonJ
In case anyone else is wondering why Ruby 3 doesn’t show when you do asdf list-all ruby :man_facepalming: do this first: asdf plugin-upd...
New
PragmaticBookshelf
“A Mystical Experience” Hero’s Journey with Paolo Perrotta @nusco Ever wonder how authoring books compares to writing articles?...
New
PragmaticBookshelf
Rails 7 completely redefines what it means to produce fantastic user experiences and provides a way to achieve all the benefits of single...
New
First poster: bot
The overengineered Solution to my Pigeon Problem. TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
New
CommunityNews
A Brief Review of the Minisforum V3 AMD Tablet. Update: I have created an awesome-minisforum-v3 GitHub repository to list information fo...
New
AstonJ
If you’re getting errors like this: psql: error: connection to server on socket “/tmp/.s.PGSQL.5432” failed: No such file or directory ...
New
AstonJ
This is a very quick guide, you just need to: Download LM Studio: https://lmstudio.ai/ Click on search Type DeepSeek, then select the o...
New