News for hackers. Stuff that matters.
Re:Reflections on 10k Hours of Programming by rckrd on Friday August 06, 2021 @10:41AM (#28087794)
Yes, maybe usually was too strong of a word - I think this varies with the language. In Go and JavaScript (where I mostly work), it's usually not that useful.

In languages like C# and Java, I've found syntactic sugar to be very useful (e.g. lambda notion)

Re:Reflections on 10k Hours of Programming by silviot on Friday August 06, 2021 @10:44AM (#28087837)
I'm under the impression that, in Javascript,

> async/await is syntactic sugar on top of the promises and provides a way to handle the asynchronous tasks in a synchronous manner.

as is stated on this website I just found with one second of googling to support my thesis: https://dmitripavlutin.com/javascript-async-await/

If that is true, I believe it's incredibly useful syntactic sugar.

Re:Reflections on 10k Hours of Programming by rckrd on Friday August 06, 2021 @10:49AM (#28087925)
Fair enough, there are clearly lots of useful syntactic shortcuts. I'm referring to things like prefix/postfix increment/decrement, object spreading vs. object rest, and ternary expressions.

I'd avoid cases where extending the language is done in a non-obvious and ambiguous way.

Re:Reflections on 10k Hours of Programming by dfee on Friday August 06, 2021 @11:08AM (#28088196)
I love me some spread operators and ternary expressions.

…mumbles something about prying those from my cold dead hands.

Re:Reflections on 10k Hours of Programming by skohan on Friday August 06, 2021 @11:58AM (#28088957)
Yeah I think there's a time and a place for ternaries, but when used correctly they're just so concise.

Like if you have super long expressions in your ternaries, or you have a bunch of nested/chained ternaries it can be hard to parse, but in a lot of cases it's so nice to get something onto one line instead of needing an if/else

Re:Reflections on 10k Hours of Programming by ensiferum on Friday August 06, 2021 @05:01PM (#28092687)
Yes in c/++ it also allows you to use const.

const foo = bar ? 1 : 2;

Without ternary you wouldn't be able to use const specifier on foo.

Re:Reflections on 10k Hours of Programming by mjcohen on Friday August 06, 2021 @01:24PM (#28090262)
Love the ternary operator in gawk. Here's some extreme examples, from a text formatter I wrote over 20 years ago. It is over 6,000 lines of awk, and I haven't used it in over 15 years.

Note: These lines should be split, but many of them are not. How do I do that? I read formatdoc, but that did not help.

; # see where text starts; mut = ((substr($0, lf1-length(lf1str), length(lf1str)) != lf1str) \ ? 1 \ : ((substr($0, lf1, 1) == " " ) \ ? (lf1+1) \ : lf1) \ ); # start of string;

---------------------------

# return file and line number with optional text; function filineg(ffilename, ffilerec, fltext) { ; # first version always gives a line number, second does not for line 1; return (ffilename \ (ffilerec == "" ? "" : (":" ffilerec)) \ ((fltext == "") \ ? "" \ : (" in \"" fltext "\"") \ )); }

------------------------------------

  outstr[2] = (head \
        ( (lnum > 1) \
         ? (substr(bigsep, 2, lnum-1) " ") \
         : (substr(spaces, 1, lnum)) \
         ) \
        (header2==""?" ":header2) null("output space if null - 5-20-98")  \
        substr(bigsep, 1, \
        ltocout-lhead-lpn-1 \
        -(lheader-lheadchop)-lnum \
        -((null_loc > 0) \
    ? lnullstring \
    : 0 \
          ) \
        ) " " pn); # parens make it line up;
----------------------

function telldepth(deptxt, dep1, dep2) { ; # change depth from dep1 to dep2; ; # good luck figuring this out in a month!; ; # tell how depth changes; recnumprint("{" deptxt " " \ ((dep1=="") \ ? ((dep2=="") \ ? ("leaves depth as is") \ : ("sets depth " dep2)\ ) \ : ("changes depth " dep1 " to " dep2) \ ) " in " filine() "}"); }

Re:Reflections on 10k Hours of Programming by frosted-flakes on Friday August 06, 2021 @03:04PM (#28091516)
Prepend each line with two spaces to format it like code.
Re:Reflections on 10k Hours of Programming by mastersummoner on Friday August 06, 2021 @12:48PM (#28089733)
I have to say, I really love the back and forth between you and the various posters in this thread. Lots of good discussion and points being made, and reasonable compromises being agreed on - or even polite disagreement with thoughtful explanations why.
Re:Reflections on 10k Hours of Programming by ajuc on Friday August 06, 2021 @12:53PM (#28089815)
Lambda isn't syntactic sugar, it's a language feature.

In Java it's kind of a syntactic sugar (lambda is a shortcut for an anonymous class with 1 method) because of historic reasons, but I'd prefer if it wasn't the case TBH.

It was always a dirty hack.