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
Hello Devtalk World! Please let us know a little about who you are and where you’re from :nerd_face:
New
AstonJ
The obligatory speed test thread :smiley: Check here: https://www.speedtest.net When complete, click on the share link and copy and pas...
New
AstonJ
I just watched this: (tldr: remove bad choices so you don’t need to use willpower) It got me thinking about ways to incre...
New
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
AstonJ
Always interested in seeing what apps people use and how they organise their phones/home screens! Here’s mine…
New
New
mafinar
I always start with excitement and then get busy on 9/10th day. This year, like the year before this, and the year before that, I intend ...
New
DevotionGeo
The Odin programming language is designed with the intent of creating an alternative to C with the following goals: simplicity high per...
New
GermaVinsmoke
Do you like to help others on stackoverflow in your free time? And what’s your reputation on Stackoverflow? :smirk::joy::rofl:
New
jaeyson
Hi!, hope everyone’s ok. Sorry if this question is ambiguous (i’ll remove this if i break some rules here). This is more like a self-ques...
New

Other popular topics Top

malloryerik
Any thoughts on Svelte? Svelte is a radical new approach to building user interfaces. Whereas traditional frameworks like React and Vue...
New
ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
Margaret
Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
New
dimitarvp
Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
New
mafinar
Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
wmnnd
Here’s the story how one of the world’s first production deployments of LiveView came to be - and how trying to improve it almost caused ...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
First poster: bot
zig/http.zig at 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 · ziglang/zig. General-purpose programming language and toolchain for maintaini...
New
AstonJ
Curious what kind of results others are getting, I think actually prefer the 7B model to the 32B model, not only is it faster but the qua...
New
OSZAR »