Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Foxfire_ posted:

code:
// This place is not a place of honor.  
// No highly esteemed deed is commemorated here… nothing valued is here.
//
// What is here is dangerous and repulsive to us. 
// The danger is still present, in your time, as it was in ours.

I'm tempted to put this in a PR and see if anyone notices.

Adbot
ADBOT LOVES YOU

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Foxfire_ posted:

code:
// This place is not a place of honor.  
// No highly esteemed deed is commemorated here… nothing valued is here.
//
// What is here is dangerous and repulsive to us. 
// The danger is still present, in your time, as it was in ours.

Honestly, this is the perfect comment for a file header, for nearly any file. Just gotta have ASCII art of the dude vomiting.

FlapYoJacks
Feb 12, 2009

Dumb Lowtax posted:

code:

if( tuition_defined = true )
    return true;
return false;



I'm the always true tuition_defined

lobsterminator
Oct 16, 2012




ratbert90 posted:

I'm the always true tuition_defined

I know modern compilers usually warn about this, but I've done quite a bit of C89 programming for retro computers lately and have gotten into the habit of

code:
if (true == tuition_defined)

if (50 == variable)
Makes it impossible to do

code:
if (true = tuition_defined)

Beef
Jul 26, 2004
Yesss, using the Yoda condition to contain the power of an unintended side effect is so :right:

edit: vvv check the name of the smiley ;)

Beef fucked around with this message at 11:20 on May 23, 2020

lobsterminator
Oct 16, 2012




Beef posted:

Yesss, using the Yoda condition to contain the power of an unintended side effect is so :right:

TBF I don't use it in modern work. I just use it when I LARP old programming.

Qwertycoatl
Dec 31, 2008

brb finding a language where "true = tuition_defined" redefines the constant "true"

Beef
Jul 26, 2004
code:
  (define true false) ; R4RS / R5RS 

Ghost of Reagan Past
Oct 7, 2003

rock and roll fun

Qwertycoatl posted:

brb finding a language where "true = tuition_defined" redefines the constant "true"

Python

EDIT: oh they seem to have changed this in Python 3, I had not tried such Stupid Python Tricks in Python 3.

Ghost of Reagan Past fucked around with this message at 12:35 on May 23, 2020

nielsm
Jun 1, 2009



Qwertycoatl posted:

brb finding a language where "true = tuition_defined" redefines the constant "true"

I remember once looking at some compiled Basic for DOS where you could pass a numeric constant (like 4) by reference to a function, and have the function modify the reference, and that would cause the constant to change value everywhere in the program. So you could make instances of the numeric literal 4 all have value 5.

Soricidus
Oct 21, 2010
freedom-hating statist shill

lobsterminator posted:

I know modern compilers usually warn about this, but I've done quite a bit of C89 programming for retro computers lately and have gotten into the habit of

code:
if (true == tuition_defined)

if (50 == variable)
Makes it impossible to do

code:
if (true = tuition_defined)

I don’t think “if (true == tuition_defined)” is any less terrible than “if (tuition_defined == true)” would have been. its even harder to accidentally assign a value if you don’t use an unnecessary explicit comparison.

If anything, yoda comparisons are a code smell, since they tell you that the author is careless and only god can help you if they ever compare two variables

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
I put "use strict" in my js so I can't typo a variable name and have the language think I meant to declare a new variable. I don't think that means you can't trust me to use variables.

Doom Mathematic
Sep 2, 2008
Yoda comparisons are a code smell because they indicate that there's no linting going on.

Absurd Alhazred
Mar 27, 2010

by Athanatos
What they should have done is standardized something if(expr; boolean valued const expr), with if(; boolean valued const expr) the mandatory form when you're not doing any assignments or changing things, to make it really hard for you to shoot yourself in the foot like this.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Doom Mathematic posted:

Yoda comparisons are a code smell because they indicate that there's no linting going on.

This is the real answer. Your IDE should be warning you "hey chief, this is an assignment, you sure you want to do that?"

Xarn
Jun 26, 2015
But I miss those because of all the other warnings :v:

Absurd Alhazred
Mar 27, 2010

by Athanatos
https://twitter.com/krisnova/status/1264415917116502025

more falafel please
Feb 26, 2005

forums poster

Volmarias posted:

This is the real answer. Your IDE should be warning you "hey chief, this is an assignment, you sure you want to do that?"

With sensible warning settings modern C++ compilers do that. IDE support is great, but that shouldn't ever see a binary anyway.

Tei
Feb 19, 2011

Foxfire_ posted:

code:
// This place is not a place of honor.  
// No highly esteemed deed is commemorated here… nothing valued is here.
//
// What is here is dangerous and repulsive to us. 
// The danger is still present, in your time, as it was in ours.

Well, this is fun but is not the spirit I want for the code where I work.

This marquee would be okay for fully cursed code. Anyway this marquee is glorious and I would order a militar parade in his honor if I where president of the united states.

Falcorum
Oct 21, 2010

Volmarias posted:

This is the real answer. Your IDE should be warning you "hey chief, this is an assignment, you sure you want to do that?"

A decent language would have just made using assigning to existing variables inside if conditions invalid code, so you could still do "if (auto blah = bleh)" but not "if (blah = bleh)". The former's useful, while the later is nearly always going to be an accidental mistake.

Maybe if epochs gain traction this could become a thing, it doesn't really change the meaning of the code, just makes one specific case invalid so there's no issue with silent behaviour changes.

e: Oops, thought this was the C++ thread, point still stands about not supporting assignment inside ifs unless assigning to a new variable. :colbert:

Falcorum fucked around with this message at 10:31 on May 24, 2020

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

more falafel please posted:

With sensible warning settings modern C++ compilers do that. IDE support is great, but that shouldn't ever see a binary anyway.

Look at this guy who looks at the warnings instead letting all 10,000 scroll past

Tei
Feb 19, 2011

Falcorum posted:

A decent language would have just made using assigning to existing variables inside if conditions invalid code, so you could still do "if (auto blah = bleh)" but not "if (blah = bleh)". The former's useful, while the later is nearly always going to be an accidental mistake.

sometimes you want to do this

if(a =foo()) { call(a); bar(a); }

do something with the result of foo, but only if is true


I don't know other people, but the times I mistake a == for a = are really small, like only once in a year

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Tei posted:

sometimes you want to do this

if(a =foo()) { call(a); bar(a); }

do something with the result of foo, but only if is true


I don't know other people, but the times I mistake a == for a = are really small, like only once in a year

It's such an easy way to screw up that it's almost irresponsible to not habitually do

code:
whatever* a = foo();
if (a) {
  call(a);
  bar(a);
}
The one exception I'll grant is in a for or while loop, where it's clear that you're using the result of foo(), because there's nowhere else it would be assigned.

code:
while (line = readln()) {
  println(line);
}

MutantBlue
Jun 8, 2001

Tei posted:

sometimes you want to do this

if(a =foo()) { call(a); bar(a); }

do something with the result of foo, but only if is true


I don't know other people, but the times I mistake a == for a = are really small, like only once in a year

In C++17 you can separate the assignment from the test:
code:
if (a = foo(); a) {
    call(a); bar(a);
}

xtal
Jan 9, 2011

by Fluffdaddy

MutantBlue posted:

In C++17 you can separate the assignment from the test:
code:
if (a = foo(); a) {
    call(a); bar(a);
}

How antiquated, modern developers write 'if err, thing; err != nil {' now

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
code:
!(a = foo()) || (call(a), bar(a));
🤔

Impotence
Nov 8, 2010
Lipstick Apathy

dougdrums posted:

code:
!(a = foo()) || (call(a), bar(a));
🤔

I see
code:
someBool && runThisStuff()
a lot in JS these days.

Doom Mathematic
Sep 2, 2008

Biowarfare posted:

I see
code:
someBool && runThisStuff()
a lot in JS these days.

Minified JS or source? Minifiers do some pretty illegible things. I wouldn't use that idiom in source except under some fairly specific conditions.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
I like doing it only for checking if a flag is set ie
code:
x.set & VALUE_SET && process_value(x);
Since it's something where I'm probably gonna have a few in a row. I saw the not-or version in some code I wrote like two years ago, but I think (hope) I was drinking when I wrote it.

Another gem for that:
code:
for (; x->set; vt[ffs(x->set)] ? vt[ffs(x->set)](x) : 0, x &= ~(1<<ffs(x)-1)) ;
where vt is a vector table with 33 values.

Tei
Feb 19, 2011

you can always write with less letters, but if you code become hard to read is time to stop

we don't want to repeat Perl

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Doom Mathematic posted:

Minified JS or source? Minifiers do some pretty illegible things. I wouldn't use that idiom in source except under some fairly specific conditions.

I got bit by this earlier this year.
code:
someBool && runThisStuff()
is legible enough on its own.

Unfortunately, that makes:
code:
 !(someBool && someOtherBool) && runThisStuff()
look legible, etc.

The problem becomes when minifiers apply de morgan's law
(e.g. !(b && u) == !b || !u)

I did have a logic error, but stepping through the minified code caused a lot of anxiety because the minifier applied de morgan's laws and actually exposed the error, but it was transformed in such a way that I had to start thinking "oh poo poo, does this optimizer apply de morgan's law and apply short circuiting to runThisStuff() in a way that I expect?"

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


i use && and || as one-line control flow all the time in JS and bash, though i'd prefer having Ruby's version of it:

code:

do_thing if some_bool

Volte
Oct 4, 2004

woosh woosh
Yeah I love having to read a line of code all the way to the end to figure out if it's even going to execute or if it's just going to yell 'not!!!' like Borat.

MrMoo
Sep 14, 2000

Taken from Perl which also has the inverse:
code:
something unless $flag

Beef
Jul 26, 2004

Volte posted:

Yeah I love having to read a line of code all the way to the end to figure out if it's even going to execute or if it's just going to yell 'not!!!' like Borat.

... && for me->poop_on();

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

MrMoo posted:

Taken from Perl which also has the inverse:
code:
something unless $flag

Nope, only acceptable for the most metal of conditions, or die, which silently fulfills the darkest wishes of the computer toucher.

It also makes skate or die valid Perl.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Volmarias posted:

It also makes skate or die valid Perl.

Random paint splatters are valid Perl.

Tei
Feb 19, 2011


Perl has a artistic license is for a reason

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Look, Perl's whole raison d'etre is to let lazy programmers be productive, and what better way to prototype than to just throw paint at the wall and see what sticks?

Adbot
ADBOT LOVES YOU

Macichne Leainig
Jul 26, 2012

by VG

Volmarias posted:

Look, Perl's whole raison d'etre is to let lazy programmers be productive, and what better way to prototype than to just throw paint at the wall and see what sticks?

Yes, paint. That's definitely what they're using. :)

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply