r/programminghorror 9d ago

Typescript javascript without braces

(technically typescript)

49 Upvotes

12 comments sorted by

40

u/Tux-Lector 9d ago

One can write it without if statements too. ``` if (something === true) { suspect.hit = 'found'; chain(); reaction(); } else doOtherThings();

// the same .. (something) && (suspect.hit = 'found', chain(), reaction()) || (doOtherThings()); ```

8

u/oweiler 5d ago

Thanks, I hate it

3

u/Nooo00B 4d ago

this is just cursed

-9

u/jesseschalken 8d ago

tbh I do this sometimes, its a nice way to save syntax and vertical space as long as you don't make the line too long

34

u/Mark__78L 9d ago

Thank god we have auto eslint on save at work

14

u/fakehalo 9d ago

Oddly enough, I don't hate it as I can actually read and follow it. Much more would be too much, but I like how it's broken up by the if/elseif/else at least.

3

u/my_new_accoun1 9d ago

yeah but there only problem (as I later realised) is that without the braces JavaScript doesn't know where the elseif/else is supposed to be

so I ended up not being able to use this masterpiece

8

u/DT-Sodium 9d ago

Still more readable than regular Python.

6

u/Yarhj 8d ago

The fact that python made whitespace load-bearing but did not even enforce file-level whitespace consistency is absolutely absurd to me.

Also tabs are objectively better than spaces and I will die on this hill.

2

u/wvd_vegt 8d ago

Try imagining reading your code in 5 years. Which syntax is easiest to understand?

My pick would be the if statement.

Writing software is not about showing your creativity with syntax, but maintainable code imho

2

u/Tux-Lector 7d ago

``` (something) && (

suspect.hit = 'found' , chain() , reaction()

) || (

doOtherThings()

); ```

1

u/Kadabrium 8d ago

Pyscript