- 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
What is AAYFN?
Admin
Always Abbreviate Your Function Names. Mouse-over texts are such a wonderful invention 😇
Admin
Ah! Thanks. Couldn’t see that on mobile.
Admin
Rather than 'Not specified', isn't the correct idiom to use 'File not found'?
Admin
Why would anyone object to Boolean-ly typed code? It's better than stringly typed code, right?
Admin
Instead of nv being the "null value", what about "no value", as in, "O don't know, I have no opinion about wether this is true or false"? Would give the program a bit of personality, quite refreshing in the age of articial intelligets...
Admin
Now a Lisp entirely implemented using C++ templates, that would be something interesting. We could even call it CLisp!
Mandatory <sarcasm> tag for those who need it. I hate C++ template programming. It's an abuse of the language and the compiler.
Admin
The text says "AAYFN(always abbreviate your function names)". No hovering needed! :-)
Admin
self.ship(it)
Admin
--Instead of nv being the "null value", what about "no value"-- or maybe ICNCNDTBVOTPV (I can neither confirm nor deny the Boolean value of that property) ?
Admin
Matz was clearly a fan of both Smalltalk and Perl, and while both of those were my favorite language at one point or another, I never caught on to Ruby. At least I successfully avoided that other Perl-inspired language, PHP. Now I'm working mostly in Dart, which can point at Smalltalk for a lot of the core features.
Admin
The other day, I had a similar problem in Python: How are values interpreted in a boolean context?
I'm a Clojure guy.
falseandnilare falsey, everything else is trueish. Shiny uses a similar approch in itsreq()function.False,Noneand""are considered falsey in this context. So far so good. Now I do various shenanigans which ultimately result in a polars data frame, which should be plotted or displayed to the user. The value is eitherNone, if for example not all required inputs are properly set, or a (possibly empty)DataFrame. Soshiny.req(data_frame())should do the trick. Alas, it doesn't. Why? Because some idiot decided, that users are stupid and using aDataFramein a boolean context is worth an exception because "the boolean value of a data frame is ambiguous". No. It is not. A data frame is neitherFalsenorNone. Hence it is trueish.And because you can obviously modify Python's behaviour for standard issues to throw unwarranted exceptions, I had to roll my own
def req(*args, **kwargs): shiny.req(*map(lambda x: isinstance(x, polars.DataFrame) or x, args), **kwargs)sighAdmin
OK, "Pretty-print a Boolean" sounds a perfectly valid function. And allowing alternative text may be unusual, but makes sense - you might want "True/False" in one place and "Yes/No" in another. But why would you not just pass in the value that you want pretty-printed? If you really need to find it by name first, it would make more sense for the caller to do that and pass the value to this function.
Admin
nvis obviouslyFILE_NOT_FOUND.Admin
That's why I have a rule whenever I'm writing coding conventions that you can never use anything other than a boolean in a boolean context. Never rely on truthiness; always be explicit about what you're checking for.
Admin
Well, a lot of languages treat nil, NULL or None as false, which is quite useful, because it treats the common case as default und reduces boiler plate. (This is also something Python gets wrong all the time. The language of stupid and useless defaults.) Only if you ever want to distinguish boolean false from nil you have to be specific, which you want in maybe 0.0000001% of the time.
The problem is two-fold: 1) Python allows to modify this behaviour. So anybody can pull the rug under you. WTF? and 2) the implementor of the polars.DataFrame chose to do so (WTF?) and the reason for it was the presumed stupidity of the user (WTF?), who obvisouly cannot be trusted with the above. Finally, instead of just giving a warning (which would be annoying, because libraries shouldn't print stuff), he decided to throw an exception for perfectly normal behaviour. W?T?F?
Admin
I can't help but imagine this function being called as part of a large "case-type" statement as an attempt at internationalization. And, of course, the entire mess copied/pasted everywhere a binary out was desired.