• (nodebb)

    That's the frist time I've seen a TDWTF code sample where a) there is no way to say which language it comes from and b) that does not matter in the least - it's still mongo WTFery and there's no language-specific corner case or detail of language evolution that could excuse it.

    (And yes pedants, I know Remy told us which it language is.)

  • (nodebb)

    This is a lesser-known dialect of LISP: LISB (Lots of Irritating Single Braces).

  • (nodebb) in reply to WTFGuy

    We might not be able to tell which language it is by looking at that, but I can say for sure that it isn't C, because }) would normally appear approximately nowhere in C89/90, nor in C99, and I have substantial doubts about its validity in the later versions. I can think of several ways to have }) in C++ (a lambda passed to a function, an initializer_list passed to a function, a temporary object constructed with {} instead of () and then passed to a function, etc.), but I still wouldn't want to see that many stacked up one inside another.

    Addendum 2024-12-05 07:11: OK, for almost sure...

  • (nodebb) in reply to WTFGuy

    I'm 99.69% sure it's JavaScript - you can see this nesting a lot, but often it's obfuscated because the code is often compacted to a single line.

  • Birion (unregistered) in reply to The Beast in Black

    I think you mean (Lots (of (Irritating (Single (Braces)))))

  • (nodebb) in reply to WTFGuy

    We might not know with 100% certainty, but JavaScript is by far the most likely. As already mentioned, it can't be C, and it's unlikely to be C++. It can't be Python, and I don't think it can be PHP. I guess it could be Java or C#, but I think those would be about as likely as C++.

  • Jonathan (unregistered)

    Perhaps it's nested callbacks in JavaScript, promises can in many cases sort this out, or failing that, async/await.

  • (nodebb) in reply to Steve_The_Cynic

    I would like to draw your attention to the following code in the Linux kernel: https://github.com/torvalds/linux/blob/master/tools/include/linux/bug.h#L9

    #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
    
  • (nodebb) in reply to WTFGuy

    It's instantly recognisable as Javascript because, as well as nested braces there are also nested parentheses mixed in. It's clearly an example of Javascript callback hell. You could do that sort of thing in other languages but only in Javascript is it regarded as a reasonable paradigm.

  • (nodebb)

    Definitely JavaScript callback hell. The mixing of parenthesis with closing braces screams lambdas/closures (as the last parameter).

    https://xkcd.com/297/

  • TheCPUWizard (unregistered)

    Ahhh.. the eternal debate between inline and factored [method calls method which calls method which...]..... There was a time when compilers could not optimize (will) so that decision made a big difference (as did loop unrolling and other techniques) There are still times where it is nice to see the flow on one (sufficiently large) linear flow on the monitor rather than jumping between locations... On the other hand there is a risk of duplicated code, and difficulty in granular testing (but be careful not to overcomplicate) Without full context, I reserve judgement.

  • Canthros (unregistered)

    It's always 'fun' when somebody decides to use the full width of their monitor.

  • Brian (unregistered)

    It's definitely possible in C# because I'm sure I've done it before, although not quite to this level of nesting. One can get some pretty ugly statements with LINQ expressions - at some point it becomes better for readability to just fall back to a normal foreach loop with function calls, but LINQ is what all the cool kids do.

  • Maddin (unregistered) in reply to Canthros

    It's always fun when somebody decided to use a tab width that is different from yours.

  • (nodebb)

    Imagine the arguments about how many spaces a tab expands to

  • Industrial Automation Engineer (unregistered)

    So years ago I wrote a compiler inspired on WhiteSpace. Only it uses parenthesis and semicolons. This was exactly what I intended: To the original developer: I salute you.

  • Richard Brantley (unregistered)

    And people complain about indenting in Python. :)

  • (nodebb)

    Are you sure this isn't just a bunch of emoticons?

  • (nodebb)

    This stuff always looks worse in TDWTF because they use 8 spaces for each indentation level.

  • Tim (unregistered)

    This layout uses tabs which display as about 8 spaces on my browser but if the developer has their IDE set to 2 spaces it might look a lot more readable

    when writing javascript in a functional style you often do have deeply nested sequences of mixed close-brace and close-parenthesis but it can still be readable as long as the function itself is less than about 20 lines long.

    In clojure (I'm not sure about other types of lisp), the editor automatically stacks all the close brackets at the end of the last line and doesn't attempt to line them up with the corresponding opens. Because you're relying on indentation to identify the structure of the code, the close braces are not needed to read it. I've often wondered whether this approach would work in javascript

  • (nodebb)

    Maybe this is the debris falling from a PHP Hadouken impact.

  • Randal L. Schwartz (github)

    It's a frequent complaint that (a) there's an "official" style for Dart, and (b) 80 columns only, please. My response is if you need more than 80 columns to express your code flow, you're (a) doing it wrong and (b) need to learn to refactor. A reasonable loop nesting or widget construction nesting will never need to go more than three or four levels deep.

  • Bart (unregistered)

    It could be Pascal, but then anything you see would be part of e nested comment.

  • Robin (unregistered) in reply to Barry Margolin

    I was about to say, TRWTF here is having 8 spaces as the indentation level. 2 is the standard in JS as far as I'm concerned. (Obviously 4 is better in languages like Python. I can't see a case for ever using 8.)

  • Duke of New York (unregistered)

    This is continuations. It's very simple continuations. No waits, no promises, no reactives. You can't travel in space, you can't go out in space without, uh, you know, with reactives! What are you going to land on, Maybe<Planet>?

  • Officer Johnny Holzkopf (unregistered)

    "Also, as someone who programs with a large font size, this is a special kind of hell for me." - Simple solution, at least in editors like "joe": ^TD2, that is, if you're using tabs for indentation; if those are spaces, then good luck (even though there are also tools for that kind of style). On the other hand, everyone is using cinema-shaped ultrawide high resolution curved 400K retinol flat panel monitors today, so this shouldn't be a problem at all. Inefficient and slow programs are compensated by more powerful hardware, and "wide code" is dealt with by wider monitors.

  • NoLand (unregistered) in reply to Jonathan

    Perhaps it's nested callbacks in JavaScript

    This makes a lot of sense. Especially, the very last line,

    });
    

    would else be the end a function expression without direct invocation, which raises the question why this wouldn't be just a normal function definition. Clearly, this must be about a function passed as an argument.

  • RLB (unregistered)

    Not just JavaScript, but JQuery JavaScript.

    And yes, indent with spaces (you can merely indent with tabs, but not do layout), and I too prefer 2. (To be honest, I prefer 3 in most monospaced fonts, but that's compatible with neither 2 nor 4 so I don't actually use it.)

    Oh, and @Richard Brantley: that is most definitely not the reason why people hate indenting in Python. There are much, much better reasons to hate Pythonic indentation rules.

  • Duke of New York (unregistered)

    Duke's law of tabs: Any sufficiently large development team will include people who are incapable of understanding/caring how tab stops work.

    You're incredibly lucky if you get past five.

  • J Waugh (unregistered) in reply to Robin

    Even in Python, four is too many

  • (author) in reply to Duke of New York

    Two. Maybe even one.

Leave a comment on “Building Blocks”

Log In or post as a guest

Replying to comment #:

« Return to Article