Some C++ style guides suggest the following naming convention for functions that crash on any error
OpenFileOrDie()
Perl also has unless() for the very purpose in OP, which is a more sensible choice.
Oh, and if you need to reinforce your belief that Perl is a mess, the single-quote character can be used as a package separator instead of "::". This was set in the 90s when nobody was quite sure of the right syntax for package separators, so it borrowed "::" from C++ and the single quote from Ada (I think).
That means the ifn't() in OP can be interpreted as calling the t() function on the ifn package.
The "::" separator is vastly preferred, though. Single quotes run havoc on syntax highlighting text editors (since they can also be used for strings). About the only time I've seen it used is a joke module, Acme::don't.
Except rethrowing an exception in C# is just throw;, anything else is a crime against the person who reads your stacktraces.
I mean, it makes sense to call ComplainToErrorAndExit just 'die', no?
this is just a menacing try/catch!
It exists, kind of. Python has this construct
for item in iterable:
...
else:
...
which always puzzles me, since it depends on a break statement execution. I always have to look it up when the else block is executed.
All known deposits were depleted
At one of my first jobs, I was tasked to rewrite a bunch of legacy Perl scripts in Python and the unless lines always made me trip up. I don't know why but it really messed with my mental flow when reading Perl code
Basic used "else".
It's nice. "if", "then", and "else". I spent a year programming a shitty roulette game on an Apple 2e back in high school. I still remember the joy of using if/then/else paired with goto to make a horrible mess of spaghetti logic.
But yeah, "else" is nice.
Using a standalone 'else' would tickle my brain in the same nice way that being able to declare a variable inside an 'if' statement as if it were a 'for' loop (which you can do in modern C++) does.
Ah clever, didn't think of doing this. Not having to encapsulate if statements in scopes would still look cleaner though
Or a rust "if let"
Ooh yes. Rust is king when it comes to this sort of inline stuff. Inline match. Mmmmmm!
🤷♂️
Let's just scrap every language except various forms of BASIC.
Please God, no. I had to unravel terminal scripting code that was written in some propriety BASIC language with basically no documentation.
Took me a chunk of time trying to figure out how it worked before I made the realization that it was BASIC
I haven't written any Ruby for years, but I still praise it in every conversation I have regarding programming languages. It's basically a much simpler Python, with some design ideas that are both beautiful and deeply strange.
Ruby was designed to evoke joy and they absolutely succeeded. Usually, programming is mostly a means to an end to me. But using Ruby just feels so amazing, it's almost impossible to even describe to somebody who has never used it before.
#define aint(x) if (!(x))
I believe that resolves the same as
ain't!(!untrue)
Is this a reference to something because I’d love to read it if you have a time to share.
It is used in ksh korn shell to see what executable responds to a command:
https://superuser.com/a/351995
Edit: Oh, what a rabbit hole: Why not use "which"? What to use then?
Legislation (which feels similar to programming languages sometimes) seems to have some keywords of its own. I remember seeing a lot of Whereas ... and Having regard to ....
Why not just ifnot? Same count of characters but an o instead of a possibly problematic single quote.
Yes... how is "reducing exclamation marks" a good thing when you do it by adding a ' (not to be confused with , ´,‘or’` ..which are all different characters).
Does this rely on the assumption that everyone uses a US QWERTY keyboard where ! happens to be slightly more inconvenient than typing '?
It's also cool when you do unless(!condition). I particularly like this.
With ahit like that its not microsoft java its now microsoft javascript
I hate seeing colloquial terms like ‘ain't’ in non-comment (ie. standardized) parts of code
reminds me of #ifndef instead of #if !defined(...)
It's not ifn't
*it'sn't
^This
OP raises a valid point
if(condition) {#block never used} else {#actually do a thing}
Vs
ifn't(condition) {#actually do a thing}
Vs
if!(condition) {#actually do a thing}
vs
if (not condition) {#actually do a thing}
Cannot start a statement with else. One can with ifn't. There is a new thing where we don't branch (which is a separate discussion).
Or am I missing the joke...
die unless $keyword == "unless";
I personally have a gut feeling of rejection for every language having the unless keyword. This is why I hardly know any PERL and Ruby for example.
I have mixed feelings towards Kotlin's takeUnless scope function (I nearly always use takeIf with a negated predicate) because my mind forgets the unless version exists.
For me I don't know if it's because I'm not english native, but reading and understanding code using unless or similar negated boolean operators makes my mind stop computing amd becomes very hard to read.
Here you dropped this:
#define ifnt(x) if (!(x))
I can actually define this in TCL:
% proc ifn't {cond cmds} {if {!$cond} {uplevel $cmds}}
% ifn't false {puts 12}
12
% ifn't true {puts 12}
%
@programming.dev
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
go to feed...
@programming.dev
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
go to feed...
I propose a new, more threatening kind of control flow.
save