Spyke
lemmy.dbzer0.com

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

do {
  /* something */
} or else {
  /* you don't want to find out */
}
191
gexreply
lemmy.world

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

OpenFileOrDie()
57
xmunkreply
sh.itjust.works

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

logUserIn() or die();

26

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.

10
Kissakireply
programming.dev

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

10

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

2

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.

4

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)

3

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.

5
startrek.website

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

99
jtkreply
lemmy.sdf.org

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.

84
Pup Birureply
aussie.zone

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

40
Falreply
yiffit.net

Which is awful and incredibly confusing. I hate ruby

20

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

3

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.

2
programming.dev

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

70
Gounreply
lemmy.ml

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

27

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

4
chaogomureply
kbin.social

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.

10
lemmy.ml

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.

7
Lmaydevreply
programming.dev

Many languages let you scope variables.

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

2
lemmy.ml

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

2

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.

1

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

3

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

4
EnderMBreply
lemmy.world

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.

7

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.

3
{
  put(a, "heartache")
  tell(me, "why")
  ain't(nothing)
  {
    put(a, "mistake")
    //...
  }
}
9

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

35

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

19

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

15
KmlSlmk64reply
lemmy.world

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

13
JoshuaENreply
lemmy.world

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

8
sh.itjust.works

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

14
xx3rawrreply
sh.itjust.works

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

6
jjjalljsreply
ttrpg.network

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

4

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

1

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

2
xia
lemmy.sdf.org

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

29
bdonvrreply
thelemmy.club

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

37

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

2
Lmaydevreply
programming.dev

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

if (x is not null)
8
Cavemanreply
lemmy.world

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

2

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

1
jtk
lemmy.sdf.org
ifn't (myNum don't= 3 && myStr ain'tnull'rblankish)
15
felbanereply
lemmy.world

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

15

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

5
feddit.it

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.

2

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.

2
lemmy.ca

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}

5

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

3

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

7

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