ifn't

2 years ago by JPDev to c/programmer_humor

0x0 191 points 2 years ago

I propose a new, more threatening kind of control flow.

do {
  /* something */
} or else {
  /* you don't want to find out */
}
path: 0 6817835, hotness: undefined, score: 191, children: 17
gex 57 points 2 years ago

Some C++ style guides suggest the following naming convention for functions that crash on any error

OpenFileOrDie()
path: 0 6817835 6819216, hotness: undefined, score: 57, children: 11
xmunk 26 points 2 years ago

PHP has the always wonderful (and perfectly functional) syntax of

logUserIn() or die();

path: 0 6817835 6819216 6819726, hotness: undefined, score: 26, children: 4
msage 6 points 2 years ago

Or Perl

path: 0 6817835 6819216 6819726 6819778, hotness: undefined, score: 6, children: 3
frezik 10 points 2 years ago

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.

path: 0 6817835 6819216 6819726 6819778 6823879, hotness: undefined, score: 10, children: 0
evatronic 3 points 2 years ago

Where do you think PHP stole it from?

path: 0 6817835 6819216 6819726 6819778 6820545, hotness: undefined, score: 3, children: 1
Kissaki 10 points 2 years ago

Personally, I like to call catched exception variables up, so for a rethrow I can throw up;.

path: 0 6817835 6819216 6826529, hotness: undefined, score: 10, children: 1
TwilightKiddy 2 points 2 years ago

Except rethrowing an exception in C# is just throw;, anything else is a crime against the person who reads your stacktraces.

path: 0 6817835 6819216 6826529 7079878, hotness: undefined, score: 2, children: 0
MonkderZweite 4 points 2 years ago

I mean, it makes sense to call ComplainToErrorAndExit just 'die', no?

path: 0 6817835 6819216 6824031, hotness: undefined, score: 4, children: 0
Vorthas 4 points 2 years ago

One of the modules in a project I'm working on is called VulkanOrDie which always makes me crack up when I see it in the compilation messages.

path: 0 6817835 6819216 6835437, hotness: undefined, score: 4, children: 0
OpenStars 3 points 2 years ago

It's funnier when you try to SysCallAndDie() :-P

(that's a real thing in perl btw - I guess that function didn't get the memo)

path: 0 6817835 6819216 6838343, hotness: undefined, score: 3, children: 0
yum13241 1 point 2 years ago

Now what about GZDoom's GoAwayAndDie();?

path: 0 6817835 6819216 6911858, hotness: undefined, score: 1, children: 0
Strawberry 38 points 2 years ago

this is just a menacing try/catch!

path: 0 6817835 6818127, hotness: undefined, score: 38, children: 0
moody 18 points 2 years ago

It_would_be_a_shame_if(condition)

path: 0 6817835 6826662, hotness: undefined, score: 18, children: 0
Mesa 8 points 2 years ago

The better try-catch. More intuitive if you ask me.

path: 0 6817835 6825620, hotness: undefined, score: 8, children: 0
jadelord 5 points 2 years ago

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.

path: 0 6817835 6846529, hotness: undefined, score: 5, children: 0
OpenStars 3 points 2 years ago

You just made me a offer I can't refuse. I go now to sleep with the fishes...

path: 0 6817835 6824320, hotness: undefined, score: 3, children: 0
OpenStars 99 points 2 years ago

Please God let this be a humorous post that somehow does not also find a way to manage to come true...

path: 0 6812457, hotness: undefined, score: 99, children: 12
jtk 84 points 2 years ago

I would have bought it if they said ifnot instead, it's the same number of characters and wouldn't require a major parser overhaul to support keywords with a ' in the name.

path: 0 6812457 6812877, hotness: undefined, score: 84, children: 9
pupbiru 40 points 2 years ago

i mean, “unless” tends to be the usual term for an “if not” keyword in languages that implement such a thing

path: 0 6812457 6812877 6814136, hotness: undefined, score: 40, children: 5
Fal 20 points 2 years ago

Which is awful and incredibly confusing. I hate ruby

path: 0 6812457 6812877 6814136 6816194, hotness: undefined, score: 20, children: 4
pupbiru 3 points 2 years ago

totally agree; just saying that if it’s GOT to be something, that something should probably be unless… unless . . .

path: 0 6812457 6812877 6814136 6816194 6825604, hotness: undefined, score: 3, children: 0
msage 3 points 2 years ago

And Perl

path: 0 6812457 6812877 6814136 6816194 6819781, hotness: undefined, score: 3, children: 1
frezik 2 points 2 years ago

I find that you need to choose carefully when to use it. Simple cases tend to be alright. Larger, more complex conditions shouldn't touch it.

path: 0 6812457 6812877 6814136 6816194 6824004, hotness: undefined, score: 2, children: 0
OpenStars 13 points 2 years ago

Yeah, to be clear, I don't like it, I don't like it one bit:-P.

path: 0 6812457 6812877 6813147, hotness: undefined, score: 13, children: 2
jaybone 4 points 2 years ago

If not anybody have time for that.

path: 0 6812457 6812877 6813147 6822918, hotness: undefined, score: 4, children: 1
OpenStars 1 point 2 years ago

*ifn't*

Oh dear Lord what have I done!? :-P

path: 0 6812457 6812877 6813147 6822918 6824221, hotness: undefined, score: 1, children: 0
mryessir 1 point 2 years ago
path: 0 6812457 6860360, hotness: undefined, score: 1, children: 1
OpenStars 1 point 2 years ago

Gulp...

 [link]

Also, just for fun, the prequel:

path: 0 6812457 6860360 6860673, hotness: undefined, score: 1, children: 0
bappity 98 points 2 years ago

cap () {

}
nocap () {

}

path: 0 6815234, hotness: undefined, score: 98, children: 1
runner_g 45 points 2 years ago

nocap(frfr){

}

path: 0 6815234 6818332, hotness: undefined, score: 45, children: 0
MagicShel 70 points 2 years ago

Reduce exclamation marks!? Great Scott!!!!! Is there a shortage of punctuation in the future!?

path: 0 6813617, hotness: undefined, score: 70, children: 4
KairuByte 19 points 2 years ago

You could have saved two, all you had to do was use the interrobang. You’re a monster.

path: 0 6813617 6816260, hotness: undefined, score: 19, children: 0
jaybone 13 points 2 years ago

1.21GB!!!

path: 0 6813617 6822934, hotness: undefined, score: 13, children: 0
SubArcticTundra 11 points 2 years ago

All known deposits were depleted

path: 0 6813617 6815794, hotness: undefined, score: 11, children: 0
fsr1967 4 points 2 years ago

Kernighan, what was I thinking?

path: 0 6813617 6822510, hotness: undefined, score: 4, children: 0
the_of_and_a_to 54 points 2 years ago
path: 0 6812395, hotness: undefined, score: 54, children: 18
JPDev 66 points 2 years ago

unlessn't

path: 0 6812395 6812443, hotness: undefined, score: 66, children: 0
Goun 27 points 2 years ago

I'm sorry, I hate the "unless" so much

path: 0 6812395 6812604, hotness: undefined, score: 27, children: 1
NotSteve_ 4 points 2 years ago

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

path: 0 6812395 6812604 6823290, hotness: undefined, score: 4, children: 0
chaogomu 10 points 2 years ago

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.

path: 0 6812395 6812875, hotness: undefined, score: 10, children: 11
SubArcticTundra 7 points 2 years ago

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.

path: 0 6812395 6812875 6815406, hotness: undefined, score: 7, children: 7
Lmaydev 2 points 2 years ago

Many languages let you scope variables.

In c# you can create an arbitrary scope to declare variables in. Most likely in others as well.

path: 0 6812395 6812875 6815406 6830687, hotness: undefined, score: 2, children: 2
SubArcticTundra 2 points 2 years ago

Ah clever, didn't think of doing this. Not having to encapsulate if statements in scopes would still look cleaner though

path: 0 6812395 6812875 6815406 6830687 6842392, hotness: undefined, score: 2, children: 1
Amaltheamannen 2 points 2 years ago

Or a rust "if let"

path: 0 6812395 6812875 6815406 6818892, hotness: undefined, score: 2, children: 1
SubArcticTundra 3 points 2 years ago

Ooh yes. Rust is king when it comes to this sort of inline stuff. Inline match. Mmmmmm!

path: 0 6812395 6812875 6815406 6818892 6824301, hotness: undefined, score: 3, children: 0
jaybone 1 point 2 years ago

Block scoped variables are bad?

path: 0 6812395 6812875 6815406 6822966, hotness: undefined, score: 1, children: 1
SubArcticTundra 1 point 2 years ago

🤷‍♂️

path: 0 6812395 6812875 6815406 6822966 6824312, hotness: undefined, score: 1, children: 0
Deceptichum 2 points 2 years ago

Let's just scrap every language except various forms of BASIC.

path: 0 6812395 6812875 6813376, hotness: undefined, score: 2, children: 2
pearsaltchocolatebar 4 points 2 years ago

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

path: 0 6812395 6812875 6813376 6813981, hotness: undefined, score: 4, children: 1
jaybone 1 point 2 years ago

Try PL/SQL.

path: 0 6812395 6812875 6813376 6813981 6822979, hotness: undefined, score: 1, children: 0
EnderMB 7 points 2 years ago

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.

path: 0 6812395 6821503, hotness: undefined, score: 7, children: 1
OskarAxolotl 3 points 2 years ago

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.

path: 0 6812395 6821503 6837479, hotness: undefined, score: 3, children: 0
marcos 6 points 2 years ago

The Perl version of it is even greater!

path: 0 6812395 6814799, hotness: undefined, score: 6, children: 0
ohlaph 53 points 2 years ago
aint (something) {
    somethingElse()
}
path: 0 6826988, hotness: undefined, score: 53, children: 3
Facebones 6 points 2 years ago

As a Virginian learning coding, this would make my damn day.

path: 0 6826988 6841192, hotness: undefined, score: 6, children: 1
Threeme2189 11 points 2 years ago
#define aint(x) if (!(x))
path: 0 6826988 6841192 6842524, hotness: undefined, score: 11, children: 0
15liam20 2 points 2 years ago

Or maybe

taint(condition) {}

path: 0 6826988 6851935, hotness: undefined, score: 2, children: 0
lung 41 points 2 years ago

ifn't(!valid) halp?

path: 0 6814486, hotness: undefined, score: 41, children: 3
Deconceptualist 40 points 2 years ago

I believe that resolves the same as

ain't!(!untrue)

path: 0 6814486 6814907, hotness: undefined, score: 40, children: 2
RagingHungryPanda 20 points 2 years ago
path: 0 6814486 6814907 6816449, hotness: undefined, score: 20, children: 1
elvith 9 points 2 years ago
{
  put(a, "heartache")
  tell(me, "why")
  ain't(nothing)
  {
    put(a, "mistake")
    //...
  }
}
path: 0 6814486 6814907 6816449 6818861, hotness: undefined, score: 9, children: 0
xmunk 35 points 2 years ago

Still not as good as whence

path: 0 6812780, hotness: undefined, score: 35, children: 6
fartsparkles 14 points 2 years ago

Is this a reference to something because I’d love to read it if you have a time to share.

path: 0 6812780 6813191, hotness: undefined, score: 14, children: 4
xx3rawr 6 points 2 years ago

Woah. I did a quick google and it's not just a meme, but actually used in some major lang's libraries.

path: 0 6812780 6813191 6814181, hotness: undefined, score: 6, children: 2
jjjalljs 4 points 2 years ago

This is one of those "modern Google/search sucks" moments because I couldn't immediately find examples of it in a programming language.

path: 0 6812780 6813191 6814181 6814778, hotness: undefined, score: 4, children: 1
xx3rawr 1 point 2 years ago

I actually used DDG and most I've seen, they're just used as arguments for functions notably in C and Python

path: 0 6812780 6813191 6814181 6814778 6842077, hotness: undefined, score: 1, children: 0
LeFrog 5 points 2 years ago path: 0 6812780 6813191 6819677, hotness: undefined, score: 5, children: 0
SubArcticTundra 2 points 2 years ago

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 ....

path: 0 6812780 6815674, hotness: undefined, score: 2, children: 0
rimjob_rainer 35 points 2 years ago

Why not just ifnot? Same count of characters but an o instead of a possibly problematic single quote.

path: 0 6823606, hotness: undefined, score: 35, children: 5
Ookami38 19 points 2 years ago

I think it's just capitalizing on a trend to add n't to otherwise noy contractions, to make them into contractions. Contractionn'ts, if you will

path: 0 6823606 6827507, hotness: undefined, score: 19, children: 0
Ferk 15 points 2 years ago

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 '?

path: 0 6823606 6824968, hotness: undefined, score: 15, children: 0
KmlSlmk64 13 points 2 years ago

If someone really wanted to add it, probably the best would be to use unless

path: 0 6823606 6824817, hotness: undefined, score: 13, children: 2
JoshuaEN 8 points 2 years ago

I really liked having unless in Ruby; a ! can be easy to miss, while unless made it clear without needing to write out != true.

path: 0 6823606 6824817 6825369, hotness: undefined, score: 8, children: 1
HexAndSquare 2 points 2 years ago

It's also cool when you do unless(!condition). I particularly like this.

path: 0 6823606 6824817 6825369 6829943, hotness: undefined, score: 2, children: 0
xia 29 points 2 years ago

"Help's with readability"? You know what else helps? Not using contractions and introducing an unbalanced single quote.

path: 0 6815016, hotness: undefined, score: 29, children: 3
bdonvr 37 points 2 years ago

If they'd'nt've done that, it'd've been better. Agreed.

path: 0 6815016 6815217, hotness: undefined, score: 37, children: 1
fsr1967 1 point 2 years ago

TIHI

path: 0 6815016 6815217 6822518, hotness: undefined, score: 1, children: 0
frezik 2 points 2 years ago

Runs havoc on parsing, too. It's bad for both humans and robots. I say we ship it.

path: 0 6815016 6824933, hotness: undefined, score: 2, children: 0
csm10495 28 points 2 years ago

Imagine the regex needed to highlight code with that extra single quote.

path: 0 6827573, hotness: undefined, score: 28, children: 0
olafurp 25 points 2 years ago

I'd take a not or "if not" operator tbh.

path: 0 6827885, hotness: undefined, score: 25, children: 7
Lmaydev 8 points 2 years ago

It has a not keyword it's used for pattern matching.

if (x is not null)
path: 0 6827885 6830578, hotness: undefined, score: 8, children: 5
olafurp 3 points 2 years ago

It also has a !=.

path: 0 6827885 6830578 6845652, hotness: undefined, score: 3, children: 3
Lmaydev 2 points 2 years ago

Pattern matching is different.

path: 0 6827885 6830578 6845652 6845891, hotness: undefined, score: 2, children: 2
olafurp 2 points 2 years ago

Yeah, I just said it since you used it with null. I used it a lot for enums

path: 0 6827885 6830578 6845652 6845891 6846796, hotness: undefined, score: 2, children: 1
Patches 2 points 2 years ago

Stuff can be two things

path: 0 6827885 6830578 6842543, hotness: undefined, score: 2, children: 0
Appoxo 3 points 2 years ago

ifnt instead of ifn't

path: 0 6827885 6847046, hotness: undefined, score: 3, children: 0
Thcdenton 17 points 2 years ago

path: 0 6830914, hotness: undefined, score: 17, children: 1
davidgro 1 point 2 years ago

Ding ding ding ding ding ding...

path: 0 6830914 6936626, hotness: undefined, score: 1, children: 0
muntedcrocodile 17 points 2 years ago

With ahit like that its not microsoft java its now microsoft javascript

path: 0 6822533, hotness: undefined, score: 17, children: 1
ohlaph 8 points 2 years ago

That's Typescript...

path: 0 6822533 6826932, hotness: undefined, score: 8, children: 0
jtk 15 points 2 years ago
ifn't (myNum don't= 3 && myStr ain'tnull'rblankish)
path: 0 6813079, hotness: undefined, score: 15, children: 3
felbane 15 points 2 years ago

Please remain calm, we are sending paramedics to your location.

path: 0 6813079 6815005, hotness: undefined, score: 15, children: 1
ripcord 2 points 2 years ago

I genuinely lol'd

path: 0 6813079 6815005 6820493, hotness: undefined, score: 2, children: 0
SubArcticTundra 5 points 2 years ago

I hate seeing colloquial terms like ‘ain't’ in non-comment (ie. standardized) parts of code

path: 0 6813079 6815840, hotness: undefined, score: 5, children: 0
AlmightySnoo 12 points 2 years ago

reminds me of #ifndef instead of #if !defined(...)

path: 0 6812408, hotness: undefined, score: 12, children: 0
vlad76 9 points 2 years ago

What's wrong with "else"

path: 0 6812299, hotness: undefined, score: 9, children: 8
NekkoDroid 43 points 2 years ago

It's not ifn't

path: 0 6812299 6812333, hotness: undefined, score: 43, children: 4
SpaceNoodle 18 points 2 years ago

*it'sn't

path: 0 6812299 6812333 6812834, hotness: undefined, score: 18, children: 2
felbane 5 points 2 years ago

I'dn't've said it like that.

path: 0 6812299 6812333 6812834 6814985, hotness: undefined, score: 5, children: 0
Scubus 1 point 2 years ago

Perchance

path: 0 6812299 6812333 6812834 6816304, hotness: undefined, score: 1, children: 0
NocturnalMorning 0 points 2 years ago

^This

OP raises a valid point

path: 0 6812299 6812333 6812974, hotness: undefined, score: 0, children: 0
Darkassassin07 5 points 2 years ago

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}

path: 0 6812299 6813577, hotness: undefined, score: 5, children: 1
gandalf_der_12te 0 points 2 years ago

vs

if (not condition) {#actually do a thing}

path: 0 6812299 6813577 6815252, hotness: undefined, score: 0, children: 0
MNByChoice 3 points 2 years ago

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...

path: 0 6812299 6813861, hotness: undefined, score: 3, children: 0
tiredofsametab 9 points 2 years ago

die unless $keyword == "unless";

path: 0 6818170, hotness: undefined, score: 9, children: 2
DieguiTux8623 2 points 2 years ago

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.

path: 0 6818170 6819283, hotness: undefined, score: 2, children: 1
devfuuu 2 points 2 years ago

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.

path: 0 6818170 6819283 6823341, hotness: undefined, score: 2, children: 0
PanArab 9 points 2 years ago

This can't be for real. I'll stick with C11 thank you.

path: 0 6837045, hotness: undefined, score: 9, children: 1
stardreamer 27 points 2 years ago

Here you dropped this:

#define ifnt(x) if (!(x))
path: 0 6837045 6838886, hotness: undefined, score: 27, children: 0
lordmauve 8 points 2 years ago

Python already has this.

path: 0 6818822, hotness: undefined, score: 8, children: 0
lurch 8 points 2 years ago

i assume "ifnot" wasn't edgy enough and makes inferior noises on custom mechanical keyboards? /s

path: 0 6812779, hotness: undefined, score: 8, children: 0
fl42v 7 points 2 years ago

This has to be illegal. I mean, it's basically suicide incitement (or whatever is the phrase for it)

path: 0 6812796, hotness: undefined, score: 7, children: 0
max 2 points 2 years ago

;-;

path: 0 6814438, hotness: undefined, score: 2, children: 0
Serpent7776 2 points 2 years ago

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}
% 
path: 0 6860719, hotness: undefined, score: 2, children: 0
programmer_humor
programmer_humor

@programming.dev

login for more options
31972
2366
7191

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.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

go to feed...