Since I’m new to JavaScript, I wrote:

πš’πš (πšŒπšŠπš•πš•πš‹πšŠπšŒπš”) { πšŒπšŠπš•πš•πš‹πšŠπšŒπš”(); }

…like an idiot. Then, I realized I should be adapting to JavaScript culture and make it inscrutable, so I re-wrote the line to:

πšŒπšŠπš•πš•πš‹πšŠπšŒπš” && πšŒπšŠπš•πš•πš‹πšŠπšŒπš”();

But I suspected there was something even more nightmarish, and sure enough, of course. This is how _real_ JavaScript developers do it:

πšŒπšŠπš•πš•πš‹πšŠπšŒπš”?.();

And by β€œreal JavaScript developers,” I mean β€œmonsters”.

My favorite thing about this conversation is that plenty of people have defended the optional chaining syntax, but nobody has objected to me calling JavaScript developers β€œmonsters.”
@gknauss I hear that for the next #monsterdon movie night, they'll be watching a documentary about JavaScript developers.
@north @gknauss Too horrifying, we try not to go for the really hard stuff.

@gknauss i’m old to javascript, but I’d use the first example. Clearer. Trick programing makes trouble.

I’d also check if callback is a function before trying to use it.

But i studied Writing Solid Code when i was newish

I spent today making fun of syntax in JavaScript, and tonight writing nested list comprehensions in Python.

It’s not hypocrisy when I do it.

@gknauss [hypocrisy(x) if x.get('user') is not 'Greg' else x for x]

@gknauss you gotta do the early return πŸ˜‰

if (!callback) {
return;
}

callback();

@gknauss as a js dev, i have worked with far too many teams who are obsessed with terse code, it's nightmarish.

That said, I _do_ like the conditional access/optional chaining operator, in both JS and C# 😳

@SudoCat @gknauss I would kill for the ?: shortcut syntax from C.

foo ?: bar instead of foo ? foo : bar

@north @gknauss in js that's usually achievable with || or ??
Aand I think c# has the ?? for doing that.
?? and ??= operators - null-coalescing operators - C# reference

The `??` and `??=` operators are the C# null-coalescing operators. They return the value of the left-hand operand if it isn't null. Otherwise, they return the value of the right-hand operand

@SudoCat @gknauss I was thinking there was some instance I ran into where I really wished I had it, but I can't come up with anything that ?? doesn't solve. It's probably just an old memory from a time before the existence of ?? in JS or maybe I'm misremembering which language it was (does PHP have that these days?).
@gknauss - the line between idiomatic and idiotic is sometimes very thin
At least, Javascript has short-circuit evaluation, unlike... C++.

@gknauss

Und in Scala gilt `Seq(7).toSet()==false`

@gknauss If you're following Screwtape methodology you have to include an uncompleted reference that falsely hints at the existence of documentation.

πšŒπšŠπš•πš•πš‹πšŠπšŒπš”?.(); // See pag

I'm not even mad
That's amazing :D

"Vitalik Buterin's Twitter account hacked to promote crypto scam"

https://web3isgoinggreat.com/?id=vitalik-buterins-twitter-account-hacked

Vitalik Buterin's Twitter account hacked to promote crypto scam

The Twitter account belonging to Vitalik Buterin, inventor and effective leader of the Ethereum project, was hacked to promote a crypto scam. A tweet posted to his compromised account advertised a "commemorative NFT" to celebrate the impending release of "proto-danksharding", which is the actual name for an upcoming change to the Ethereum protocol.However, the link was a scam, and anyone who connected their wallet risked having their wallet drained of its cryptocurrency and NFTs. Some blue-chip NFTs were stolen, including two CryptoPunks (a collection with a floor price of around 47 ETH, or $76,800). Altogether, stolen assets surpassed $650,000 in value within a few hours of the theft according to zachxbt, though this counts notoriously difficult-to-value NFTs.The tweet was taken down within twenty minutes of being posted. All in all, posting a link to a wallet drainer was probably among the least effective things the attacker could do with the Twitter account of a person whose word can dramatically move markets.It did seem to be something of a stark warning to some in the crypto world, however, who expressed sentiments along the lines of "if Vitalik can get hacked, anyone can."

Web3 is Going Just Great

@gknauss Yes, monsters! Using this is really weird!

Rubyists know how weird this would be, therefore in Ruby we do

callback&.()

@gknauss

callback && callback()

is an idiom from C.

In Linux kernel source directory:

$ git grep -E -- '->([a-z]+).*&&.*->\1\('
arch/powerpc/platforms/powermac/low_i2c.c: if (bus->open && (rc = bus->open(bus)) != 0) {
arch/x86/kernel/apic/probe_64.c: if ((*drv)->probe && (*drv)->probe()) {
arch/x86/kernel/pci-dma.c: if (p && p->detect && p->detect() > 0) {
arch/x86/kvm/cpuid.c: if (ent->qualifier && !ent->qualifier(ent))

[ ... numerous hits]

@gknauss They probably all result in the same machine instructions being run. The devs who prefer terse source code are somewhat of a mystery. Maybe they are worried about carpal tunnel and want to avoid typing too much?

@gknauss Good news is that you’re only ignorant and not an idiot. In pre-TypeScript days, I would have written something like this:

function ugh() {
alert("called it");
}

if (typeof ugh === "function") {
ugh();
}

@capndesign If the name somehow got assigned something other than a function β€” like a string got passed to the callback assignment instead of a function β€” wouldn’t you rather crash rather than silently not call it? That would be harder to debug.
@gknauss Oh, absolutely. I did not think particularly hard about your actual problem, as is standard for code reviews.

@gknauss better:

if (typeof callback === β€œfunction”) { callback() }

@gknauss you will write machine code and you will like it!

@gknauss

My 1st paid programming job was coding in MUMPS.

In MUMPS you can, or at least could, abbreviate commands to the 1st letter, use offsets, i.e. Go to {line_label} + 5, and indirection, i.e. Go @{variable_name} where {variable_name} was previously set to {line_label} + 5.

So...

s v1="nextloop + 5"
g @v1

Someone adds a line for an additional condition 2 lines after 'nextloop' and night support has to figure out why things are crashing...
Talk about monsters pretending to be coders.

@gknauss im no javascript dev but… I don’t hate what you’ve done here
@gknauss ahahah yes javascript is truly a beast ...
@gknauss just so you know, that's what such a toot looks like for some of us

@gknauss you should get Javascript: the Good Parts by Douglas Crockford.

If the code is there, use it. If it's not, leave it to the monsters.

(The book could be a bit outdated in missing latest features, but the basics haven't gone anywhere with the new hotness...)

@gknauss iirc c# has this to, you can do object?.Method()
@gknauss I guess I’m a monster then
@gknauss Speaking of monsters… I wish you’d use text for your code examples, not a bunch of special math characters that: a) won’t run if copy them in the browser, b) will be verbosely spelled one by one if read via a screen reader.
@gknauss Find and replace "real" with "Experienced". If you came across callback?(); would you intuitively know what it does? That's a question that is always worth asking. I am not being critical, I am playing with a thought experiment, for myself. I'll see when I get to use this snippet of code.

@gknauss

I...

Listen it makes sense to me when I do it ._.

@gknauss Is it bad that I think that last one is kind of cute?
@gknauss Stop. You're making perl jealous!