ifn't

720 points · 116 comments · view on lemmy.world

116 Comments

0x0@lemmy.dbzer0.com · 191 pts · 2y (17 replies)

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

do {
  /* something */
} or else {
  /* you don't want to find out */
}
gex@lemmy.world · 57 pts · 2y (11 replies)

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

OpenFileOrDie()
xmunk@sh.itjust.works · 26 pts · 2y (4 replies)

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

logUserIn() or die();

msage@programming.dev · 6 pts · 2y (3 replies)

Or Perl

frezik@midwest.social · 10 pts · 2y

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.

evatronic@lemm.ee · 3 pts · 2y (1 reply)

Where do you think PHP stole it from?

msage@programming.dev · 2 pts · 2y

Bash?

Kissaki@programming.dev · 10 pts · 2y (1 reply)

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

TwilightKiddy@programming.dev · 2 pts · 2y

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

MonkderZweite@feddit.ch · 4 pts · 2y

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

Vorthas@programming.dev · 4 pts · 2y

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.

OpenStars@startrek.website · 3 pts · 2y

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)

yum13241@lemm.ee · 1 pts · 2y

Now what about GZDoom's GoAwayAndDie();?

Strawberry@lemmy.blahaj.zone · 38 pts · 2y

this is just a menacing try/catch!

moody@lemmings.world · 18 pts · 2y

It_would_be_a_shame_if(condition)

Mesa@programming.dev · 8 pts · 2y

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

jadelord@discuss.tchncs.de · 5 pts · 2y

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.

OpenStars@startrek.website · 3 pts · 2y

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

OpenStars@startrek.website · 99 pts · 2y (12 replies)

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

jtk@lemmy.sdf.org · 84 pts · 2y (9 replies)

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.

pupbiru@aussie.zone · 40 pts · 2y (5 replies)

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

Fal@yiffit.net · 20 pts · 2y (4 replies)

Which is awful and incredibly confusing. I hate ruby

pupbiru@aussie.zone · 3 pts · 2y

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

msage@programming.dev · 3 pts · 2y (1 reply)

And Perl

NigelFrobisher@aussie.zone · 3 pts · 2y

And my axe!

frezik@midwest.social · 2 pts · 2y

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.

OpenStars@startrek.website · 13 pts · 2y (2 replies)

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

jaybone@lemmy.world · 4 pts · 2y (1 reply)

If not anybody have time for that.

OpenStars@startrek.website · 1 pts · 2y

*ifn't*

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

mryessir@lemmy.sdf.org · 1 pts · 2y (1 reply)
[ removed ]
OpenStars@startrek.website · 1 pts · 2y

Gulp...

 [link]

Also, just for fun, the prequel:

bappity@lemmy.world · 98 pts · 2y (1 reply)

cap () {

}
nocap () {

}

runner_g@lemmy.blahaj.zone · 45 pts · 2y

nocap(frfr){

}

MagicShel@programming.dev · 70 pts · 2y (4 replies)

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

KairuByte@lemmy.dbzer0.com · 19 pts · 2y

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

jaybone@lemmy.world · 13 pts · 2y

1.21GB!!!

SubArcticTundra@lemmy.ml · 11 pts · 2y

All known deposits were depleted

fsr1967@lemmy.world · 4 pts · 2y

Kernighan, what was I thinking?

the_of_and_a_to@lemmy.world · 54 pts · 2y (18 replies)
[ removed ]
JPDev@programming.dev · 66 pts · 2y

unlessn't

Goun@lemmy.ml · 27 pts · 2y (1 reply)

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

NotSteve_@lemmy.ca · 4 pts · 2y

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

chaogomu@kbin.social · 10 pts · 2y (11 replies)

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.

SubArcticTundra@lemmy.ml · 7 pts · 2y (7 replies)

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.

Amaltheamannen@lemmy.ml · 2 pts · 2y (1 reply)

Or a rust "if let"

SubArcticTundra@lemmy.ml · 3 pts · 2y

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

Lmaydev@programming.dev · 2 pts · 2y (2 replies)

Many languages let you scope variables.

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

SubArcticTundra@lemmy.ml · 2 pts · 2y (1 reply)

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

Lmaydev@programming.dev · 1 pts · 2y

It's handy if you're creating temp variables for single use that you don't need to use again.

Although I admit I've only ever done it a couple times lol

Again in c# you can omit the scope and only the next statement is part of an if or loop.

jaybone@lemmy.world · 1 pts · 2y (1 reply)

Block scoped variables are bad?

SubArcticTundra@lemmy.ml · 1 pts · 2y

🤷‍♂️

Deceptichum@kbin.social · 2 pts · 2y (2 replies)

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

pearsaltchocolatebar@discuss.online · 4 pts · 2y (1 reply)

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

jaybone@lemmy.world · 1 pts · 2y

Try PL/SQL.

EnderMB@lemmy.world · 7 pts · 2y (1 reply)

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.

OskarAxolotl@lemmy.world · 3 pts · 2y

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.

marcos@lemmy.world · 6 pts · 2y

The Perl version of it is even greater!

ohlaph@lemmy.world · 53 pts · 2y (3 replies)
aint (something) {
    somethingElse()
}
Facebones@reddthat.com · 6 pts · 2y (1 reply)

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

Threeme2189@lemm.ee · 11 pts · 2y
#define aint(x) if (!(x))
15liam20@lemmy.world · 2 pts · 2y

Or maybe

taint(condition) {}

lung@lemmy.world · 41 pts · 2y (3 replies)

ifn't(!valid) halp?

Deconceptualist@lemm.ee · 40 pts · 2y (2 replies)

I believe that resolves the same as

ain't!(!untrue)

RagingHungryPanda@lemm.ee · 20 pts · 2y (1 reply)
[ removed ]
elvith@feddit.de · 9 pts · 2y
{
  put(a, "heartache")
  tell(me, "why")
  ain't(nothing)
  {
    put(a, "mistake")
    //...
  }
}
rimjob_rainer@discuss.tchncs.de · 35 pts · 2y (5 replies)

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

Ookami38@sh.itjust.works · 19 pts · 2y

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

Ferk@kbin.social · 15 pts · 2y

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

KmlSlmk64@lemmy.world · 13 pts · 2y (2 replies)

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

JoshuaEN@lemmy.world · 8 pts · 2y (1 reply)

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

HexAndSquare@lemmy.world · 2 pts · 2y

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

xmunk@sh.itjust.works · 35 pts · 2y (6 replies)

Still not as good as whence

fartsparkles@sh.itjust.works · 14 pts · 2y (4 replies)

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

xx3rawr@sh.itjust.works · 6 pts · 2y (2 replies)

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

jjjalljs@ttrpg.network · 4 pts · 2y (1 reply)

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

xx3rawr@sh.itjust.works · 1 pts · 2y

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

LeFrog@discuss.tchncs.de · 5 pts · 2y

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?

SubArcticTundra@lemmy.ml · 2 pts · 2y

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

xia@lemmy.sdf.org · 29 pts · 2y (3 replies)

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

bdonvr@thelemmy.club · 37 pts · 2y (1 reply)

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

fsr1967@lemmy.world · 1 pts · 2y

TIHI

frezik@midwest.social · 2 pts · 2y

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

csm10495@sh.itjust.works · 28 pts · 2y

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

olafurp@lemmy.world · 25 pts · 2y (7 replies)

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

Lmaydev@programming.dev · 8 pts · 2y (5 replies)

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

if (x is not null)
olafurp@lemmy.world · 3 pts · 2y (3 replies)

It also has a !=.

Lmaydev@programming.dev · 2 pts · 2y (2 replies)

Pattern matching is different.

olafurp@lemmy.world · 2 pts · 2y (1 reply)

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

Lmaydev@programming.dev · 1 pts · 2y

The type matching is the most common thing I use it with. Combined with inline variables.

if (x is string { Length: 5} s)
{
    // do stuff with s
}

And switch expressions.

As a side note inline variables are amazing haha

Patches@sh.itjust.works · 2 pts · 2y

Stuff can be two things

Appoxo@lemmy.dbzer0.com · 3 pts · 2y

ifnt instead of ifn't

muntedcrocodile@lemmy.world · 17 pts · 2y (1 reply)

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

ohlaph@lemmy.world · 8 pts · 2y

That's Typescript...

Thcdenton@lemmy.world · 17 pts · 2y (1 reply)

davidgro@lemmy.world · 1 pts · 2y

Ding ding ding ding ding ding...

jtk@lemmy.sdf.org · 15 pts · 2y (3 replies)
ifn't (myNum don't= 3 && myStr ain'tnull'rblankish)
felbane@lemmy.world · 15 pts · 2y (1 reply)

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

ripcord@lemmy.world · 2 pts · 2y

I genuinely lol'd

SubArcticTundra@lemmy.ml · 5 pts · 2y

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

AlmightySnoo@lemmy.world · 12 pts · 2y

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

vlad76@lemmy.sdf.org · 9 pts · 2y (8 replies)

What's wrong with "else"

NekkoDroid@programming.dev · 43 pts · 2y (4 replies)

It's not ifn't

SpaceNoodle@lemmy.world · 18 pts · 2y (2 replies)

*it'sn't

felbane@lemmy.world · 5 pts · 2y

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

Scubus@sh.itjust.works · 1 pts · 2y

Perchance

NocturnalMorning@lemmy.world · 0 pts · 2y

^This

OP raises a valid point

Darkassassin07@lemmy.ca · 5 pts · 2y (1 reply)

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}

gandalf_der_12te@feddit.de · 0 pts · 2y

vs

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

MNByChoice@midwest.social · 3 pts · 2y

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

PanArab@lemmy.world · 9 pts · 2y (1 reply)

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

stardreamer@lemmy.blahaj.zone · 27 pts · 2y

Here you dropped this:

#define ifnt(x) if (!(x))
tiredofsametab@kbin.social · 9 pts · 2y (2 replies)

die unless $keyword == "unless";

DieguiTux8623@feddit.it · 2 pts · 2y (1 reply)

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.

devfuuu@lemmy.world · 2 pts · 2y

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.

lurch@sh.itjust.works · 8 pts · 2y

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

lordmauve@programming.dev · 8 pts · 2y

Python already has this.

fl42v@lemmy.ml · 7 pts · 2y

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

max@lemmy.blahaj.zone · 2 pts · 2y

;-;

Serpent7776@programming.dev · 2 pts · 2y

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}
%