6 ms·
I don't understand how somebody can code like this and reason/control anything about the program execution :) async (() => (e) { try { await doSomething();
by 0xCE0 1y ago
I don't understand how somebody can code like this and reason/control anything about the program execution :)
async (() => (e) {
try { await doSomething();
while (!done) { ({ done, value } = await reader.read()); }
promise
.then(goodA, badA)
.then(goodB, badB)
.catch((err) => { console.error(err); }
catch { }
finally { using stack = new DisposableStack();
stack.defer(() => console.log("done.")); }
});
- pwdisswordfishz 1y agoIndenting helps.
- kubb 1y agoAlso practice, programming is hard, but just because one person doesn't understand something, doesn't mean it's impossible or a bad idea.
- xg15 1y agoAlso, sticking to one style and not mixing all the wildly different approaches to do the same thing. JS, like HTML has the special property that you effectively cannot make backwards-incompatible changes ever, because that scrappy webshop or router UI that was last updated in the 90s still has to work. But this means that the language is more like an archeological site with different layers of ruins and a modern city built on top of it. Don't use all the features only because they are available.
- wpollock 1y agoThere used to be a great book for this, "JavaScript The Good Parts". Is there a well-respected equivalent for JavaScript in 2025?
- gavinray 1y agoBy programming in the language for a living and being familiar with the semantics of the language's keywords -- likely the same way anyone else understands their preferred language? People write Haskell for a living, after all.
- johnisgood 1y agoAnd Lisp, and Forth... :D
- 90s_dev 1y agoLisp I can understand to some degree... but writing Forth for a living? I know about 20-30 languages, but that one is Greek to me.
- johnisgood 1y agoStack-based or concatenative languages can be difficult to understand, but as with anything, you may / could get used to it. :) I prefer Factor[1] over Forth, however. Maybe you'll like it! [1] https://factorcode.org/ https://factorcode.org/
- 90s_dev 1y agoIt's not that they're hard to understand, it's that they're much denser. From Factor's examples page: > 2 3 + 4 * . There's a lot more there to mentally parse than: > (2 + 3) * 4 It's the same as when Rob Pike decries syntax highlighting. No, it's very useful to me. I can read much quicker with it. It's the same principle behind how we use heuristics to much more quickly read words by sipmly looking at the begninnings and ends of each word, and most of the time don't even notice typos.
- johnisgood 1y agoWell, I guess it might boil down to how one "thinks"? Some people prefer: 2 3 + 4 * Some other people prefer: (* 4 (+ 2 3)) And some other people prefer: (2 + 3) * 4 I personally find the last one easier to read or understand, but I have had my fair share of Common Lisp and Factor. :D Syntax highlighting is useful for many people, including me. I can read much quicker with it, too. I know of some people who write Common Lisp without syntax highlighting though. :)
- snickerbockers 1y agoThat's the neat part, you don't. 90% percent of webdev is "upgrading" things in ways nobody asked for or appreciates because it's just taken for granted that your codebase will grow mold or something if it isn't stirred often enough and the other 10% of the work is fixing legitimate problems resulting from the first 90%. Of course, no probability is ever actually 1.0 so there will be rare occasions that you need to understand something that ChatGP-err, sorry my bad, i meant to say "something that you" wrote more than a year ago you suggest to your boss that this bug should be preserved until next time there's a new hire because it would make a great "jumping-on" point and until then the users will still be able to get work done by using the recommended work-around, whic his installing windows XP Pirate Edition onto a VM and using IE6 to get into the legacy-portal that somehow inexplicably still exists 20 years after the corporate merger that was supposed to make it obsolete.
- exe34 1y agoYou wrote out loud what I've been thinking quietly.
- gchamonlive 1y agoFrom the lack of punctuation I think you can also rap it out loud.
- snickerbockers 1y agooh my god youre right https://soundcloud.com/snickerbockers/corporate-it-webdevs-frfr?si=fcc87d8b924249999fa51112e87c6cb8&utm_source=clipboard&utm_medium=text&utm_campaign=social_sharing https://soundcloud.com/snickerbockers/corporate-it-webdevs-f...
- gchamonlive 1y agoThis is genius! For the first time in my life my pedantry got rewarded.
- 1y ago
- 77pt77 1y agoLLMs will do only this and you'll love it. Maybe not love it, but you really won't have a choice.
- stephenr 1y agoI mean we're talking about a language community where someone created a package to tell if a variable is a number... and it gets used *a lot*. That JavaScript has progressed so much in some ways and yet is still missing basic things like parameter types is crazy to me.
- chrisweekly 1y agoThe overwhelming majority of serious work in JS is authored in TypeScript.
- stephenr 1y agoThat just Sounds like an even stronger argument to add types to the language.
- chrisweekly 1y agoCould be.
- paulddraper 1y agoYeah. The hard part is that types are very hard/complex, with many tradeoffs. A standard with strong backwards compat and is interpreted consistently is hard (see Python).
- cluckindan 1y agoThat is a ”no true Scotsman” argument.
- chrisweekly 1y agoHow so? GP complained about JS lack of types. I pointed out that most JS actually benefits from types, given it's typically authored in TS. No moving goalposts, no "true Scotsman" arg.
- 1y ago
- notpushkin 1y agoTo embed code on HN, add 2 or more spaces at the beginning of each line: async (() => (e) { try { await doSomething(); while (!done) { ({ done, value } = await reader.read()); } promise .then(goodA, badA) .then(goodB, badB) .catch((err) => { console.error(err); } catch { } finally { using stack = new DisposableStack(); stack.defer(() => console.log("done.")); } }); (indentation preserved as posted by OP – I don't understand how somebody can code like this either :-)
- 90s_dev 1y agoFor starters, your code is so full of serious syntax errors that in some places it's not even close to valid JavaScript. This is my best guess reconstruction: (async (e) => { await doSomething() while (!done) { ({ done, value }) = await reader.read() } promise .then(goodA, badA) .then(goodB, badB) .catch(err => console.log(err)) .finally(() => { using stack = new DisposableStack() stack.defer(() => console.log('done.')) }) })() But more importantly, this isn't even close to anything a reasonable JS dev would ever write. 1. It's not typical to mix await and while(!done), I can't imagine what library actually needs this. You usually use one or the other, and it's almost always just await: await doSomething() const value = await readFully(reader) 2. If you're already inside an Async IIFE, you don't need promise chains. Just await the stuff as needed, unless promise chains make the code shorter and cleaner, e.g.: const json = await fetch(url).then(r => r.json()) 3. Well designed JS libraries don't usually stack promise handlers like the {good,bad}{A,B} functions you implied. You usually just write code and have a top level exception handler: using stack = new DisposableStack() stack.defer(() => console.log('done.')) try { const goodA = await promise const goodB = await goodA const goodC = await goodB return goodC } catch(e) { myLogErr(e) } // finally isn't needed, that's the whole point of DisposableStack 4. We don't usually need AIIFEs anymore, so the outer layer can just go away.
- postalrat 1y ago[flagged]
- soulofmischief 1y agoThat is a matter of opinion. JavaScript allows you to use either convention at your preference. Personally, I feel my code looks much, much cleaner without semicolons. I also use whitespace liberally.
- 90s_dev 1y agoFor the longest time, I used them just in case it would otherwise cause a bug. But TypeScript fully takes this into account and checks for all these scenarios.
- jitl 1y agoyou can write horrid code intentionally in any programming language
- mrweasel 1y agoIt just seems like it's happening way more often in JavaScript, but I've seen absolute horrid and confusing Python as well. The JavaScript syntax wasn't great to begin with, and as features are added to the language it sort of has to happen within the context of what's possible. It's also becoming a fairly large language, one without a standard library, so things just sort of hang out in a global namespace. It's honestly not to dissimilar to PHP, where the language just grew more and more functions. As others point out there's also some resemblance to C#. The problem is that parts of the more modern C# is also a confusing mess, unless you're a seasoned C# developer. The new syntax features aren't bad, and developers are obviously going to use them to implement all sorts of things, but if you're new to the language they feel like magical incantations. They are harder to read, harder to follow and doesn't look like anything you know from other language. Nor are they simple enough that you can just sort of accept them and just type the magical number of brackets and silly characters and accept that it somehow work. You frequently have no idea of what you just did or why something works. I feel like Javascript has reached the point where it's a living language, but because of it's initial implementation and inherit limits, all these great features feel misplaced, bolted on and provides an obstacle for new or less experienced developers. Javascript has become an enterprise language, with all the negative consequences and baggage that entails. It's great that we're not stuck with half a language and we can do more modern stuff, it just means that we can't expect people to easily pick up the language anymore.
- neonsunset 1y ago> parts of the more modern C# is also a confusing mess Do you have any examples?
- mrweasel 1y agoFor me, personally, heavy use of the => operator (which happens to coinside with my main complaint of a lot JavaScript code and anonymous functions). You can avoid it, but is pretty standard. Very specifically I also looking into JWT authentication in ASP.NET Core and found the whole thing really tricky to wrap my head around. That's more of a library, but I think many of the usage examples ends up being a bunch of spaghetti code.
- TheRealPomax 1y agoIt all starts with being well-formatted and having a proper code editor instead of just a textarea on a webpage, so you'd get the many error notices for that code (because it sure as hell isn't valid JS =) And of course, actually knowing the language you use every minute of the day because that's your job helps, too, so you know to rewrite that nonsense to something normal. Because mixing async/await and .then.catch is ridiculous, and that while loop should never be anywhere near a real code base unless you want to get yelled at for landing code that seems intentionally written to go into a spin loop under not-even-remotely unusual circumstances.
- mattlondon 1y agoNo worse than C++, frankly.