- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
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.)
Admin
This is a lesser-known dialect of LISP: LISB (
Lots of Irritating Single Braces
).Admin
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...
Admin
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.
Admin
I think you mean (Lots (of (Irritating (Single (Braces)))))
Admin
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++.
Admin
Perhaps it's nested callbacks in JavaScript, promises can in many cases sort this out, or failing that, async/await.
Admin
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
Admin
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.
Admin
Definitely JavaScript callback hell. The mixing of parenthesis with closing braces screams lambdas/closures (as the last parameter).
https://xkcd.com/297/
Admin
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.
Admin
It's always 'fun' when somebody decides to use the full width of their monitor.
Admin
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.
Admin
It's always fun when somebody decided to use a tab width that is different from yours.
Admin
Imagine the arguments about how many spaces a tab expands to
Admin
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.
Admin
And people complain about indenting in Python. :)
Admin
Are you sure this isn't just a bunch of emoticons?
Admin
This stuff always looks worse in TDWTF because they use 8 spaces for each indentation level.
Admin
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
Admin
Maybe this is the debris falling from a PHP Hadouken impact.
Admin
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.
Admin
It could be Pascal, but then anything you see would be part of e nested comment.
Admin
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.)
Admin
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>?
Admin
"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.
Admin
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.
Admin
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.
Admin
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.
Admin
Even in Python, four is too many
Admin
Two. Maybe even one.