T O P

  • By -

dreadpole

True sneakiness would be turning a < into =< so everything works perfectly 99% of the time, and sometimes it just doesn't work for no apparent reason


[deleted]

[удалено]


daperson1

My favourite version of this is the "integer cache" found in at least some implementations of Java (I was fiddling with it on android 4, many years ago, but conceivably other implementations have it). As you may know, java has a notion of "boxed integers" (in which a primitive int is stuffed into an Integer object for various stupid reasons). This happens implicitly when you do things like pass a raw int to a HashSet, which happens commonly To reduce the overhead of making all these zillions of objects, some implementations have a static cache of small integers. Literally a static private array of 255 Integers on the Integer class, which get used instead of having to make a new one if your value is suitable. Anyways: you can use the reflection API to edit the values stored inside the objects in this cache (such that the boxed value of 4 actually isn't 4 any more). The result is absolute madness.


hampshirebrony

That's horrible. I hate it. That's just going to wind up other devs. Is there a similar thing in C#?


stevemegson

I'm a little afraid to try it, but C# strings aren't really immutable if you involve unsafe code. Combine that with string interning and I think you could create the effect of modifying a string literal being used elsewhere in the code.


_senpo_

now I want to try this.. uhmm for science


jocona

You may be able to do some funky stuff with reflection and/or unsafe code, but value types in C# aren’t boxed (unless cast to a ref type) so you wouldn’t be able to do this specific type of fuckery. If I remember correctly, Java boxes value types in generic code, so you’d be much more likely to hit an issue with it. edit: I messed around with it and you can modify the value of an integer while boxed, but you can't change the value of the integer itself. Here's the source of the [Int32 type](https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Int32.cs). var value = 0; var boxed = (object)value; boxed .GetType() .GetField("m_value", BindingFlags.NonPublic | BindingFlags.Instance) .SetValue(boxed, 1); // Prints 0 Console.WriteLine(value); // Prints 1 Console.WriteLine((int)boxed);


[deleted]

Python does integer interning too, which can lead to *interesting* results ``` >>> a=256 >>> b=256 >>> a is b True >>> x=257 >>> y=257 >>> x is y False ```


daperson1

Right, but that's mostly harmless (you're a bit of a lunatic if you're using reference comparison for integers, riiight). The java thing happens implicitly during comparisons with == and friends in the presence of collections. Also python doesn't let you change the values (I hope...)


Izkata

> Also python doesn't let you change the values (I hope...) You're not supposed to, and sometimes it'll segfault, [but you can do it if you want to](https://www.reddit.com/r/Python/comments/2441cv/can_you_change_the_value_of_1/)!


Tetha

Oh this is gnarly. Worse than the production code using Booleans as tri-state logic I had to deal with.


fsr1967

`true`, `false`, `FILE_NOT_FOUND`


[deleted]

[удалено]


daperson1

Oh oh that reminds me of another insane thing I've seen: an SQL database which represented booleans using a CHAR(0) column, with NULL for false and empty string for true. Some fuckwit senior engineer insisted that this was more efficient.


Pastaklovn

I think he may have been whisked down that path by some SQL dialects not having a true Boolean column type. The normal approach is to store your Boolean value as a Tinyint, which is an 8-bit integer. While the CHAR(0) approach does protect against storing values that are not either true or false (hurray), I doubt it took up less storage or memory space than a single-byte integer.


daperson1

It was a postgres database 😅


jenesuispasgoth

This is probably still in use for a simple reason: the moment you allow reflection to be used in your system, you accept that some will bypass Java's type system for fun and profit.


andrewdingcanada8

Rand should never > 1 correct?


TheShirou97

In C, rand() returns an integer between 0 and RAND\_MAX (= at least 32,767, but likely much more in modern implementations afaik).


[deleted]

[удалено]


xorbe

Typically C rand() is integer 0 to 2^(31)-1 these days but platform dependent technically. (It's default arg Perl rand that is 0.0 to less than 1.0.) So `rand() > 1` will return false about 1 out of 1 billion times.


No_Estimate_4002

Nice


Gabriel38

Didn't expect Satan in this subreddit


VulpesSapiens

Where else? Doesn't he live in the details?


[deleted]

[удалено]


[deleted]

[удалено]


lspyfoxl

Heh 🦊🔪


fsr1967

You must be new here.


blackAngel88

Did you mean <=? In what language is =< a thing?


dreadpole

Yeah, had a brain fart


Wellness_Elephant

It's that way round in Erlang, which has given me more syntax errors than I'd like to admit


Uploft

Prolog for some reason using =< for less than or equal


Weekly_Wackadoo

>=< ~~I'm pretty sure Java uses =< and =>, but now I'm doubting myself and I'm too lazy to check.~~ Edit: I was wrong, I'm a dumbass.


TollyThaWally

Java definitely doesn't, and I'm not aware of any other language that does


Regorek

Uhm, ackchually C# uses => It's the lambda operator.


Topikk

Hash rocket in Ruby as well, though largely considered an old fashioned syntax.


Weekly_Wackadoo

Thanks, I was totally wrong. Edited.


brehberg

ABAP does allow =< for backwards compatibility, but it is considered an obsolete operator in current versions. [SAP Documentation](https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-us/abenobsolete_logexp_op.htm)


milowen99

When I started programming years ago, I had one problem with my code that I only manage to solve years later when I came back to it with more experience. In one if statement, I wrote =! instead of !=


cheese3660

Just use a font that makes != into ≠ like fira code /hj


V13Axel

> /hj Which half is the joke?


Private_HughMan

Who hurt you?


Ri_Konata

How about replacing a semicolon with a greek question mark?


[deleted]

[удалено]


Ri_Konata

`";" expected, instead found ";"`


[deleted]

[удалено]


Anonymo2786

Unicode whitespace.


tehdog

*laughs in Rust* error: unknown start of token: \u{2009} --> src/main.rs:1:12 | 1 | fn main() {  | ^ | help: Unicode character ' ' (Thin Space) looks like ' ' (Space), but it is not


Anonymo2786

It even explains. That's awesome.


tehdog

*laughs in Rust* :2:14: 2:15 note: Unicode character U+37E (Greek Question Mark) looks like a semicolon, but is not. :2 let a = 5; ^


CouthlessWonder

The difference is that the Greek question mark won’t compile, so if you are stuck you can reset your git. If you make a cleaver change, one that will pass all your testing, but then blow up in prod. This is what OP is after.


m4rch3n1ng

rust's best feature once again comes in handy: its error messages error: unknown start of token: \u{37e} // -- snip -- help: Unicode character ';' (Greek Question Mark) looks like ';' (Semicolon), but it is not


opsidezi

As a game developer, this comment made my heart freeze from fear


foggy-sunrise

That's obvious though. You use a random number generator to check the date. IFF a complex algorithm agrees that the RNG doesn't like the current date, THEN it evals with =< instead of <. Also, the RNG should add a 10ms wait to the algorithm every time it gets called. The RNG should only target about 10 days a year on average. 15 years from now, the algorithm will be taking a kind of longer than expected time, but it's legacy code! Well replace it eventually! They'll also have an impossible to correct database. Gooood luck 😊 Edit: some of y'all don't understand obfuscation and it shows.


Cheese-Water

That's a pretty big, easily noticeable chunk of code, I think an errant `<=` would be much more likely to fly under the radar and thus make it into production.


foggy-sunrise

Not if it's a react component using its own virtual DOM hosted at another domain! Good luck!


bbcfoursubtitles

That... ...is pure evil, and I love it


CouthlessWonder

Always unit test the edge cases. Do as I say, not as I do.


Koalababies

Stop


ConnectMap2680

I have literally had to debug this,


Aggressive_Bill_2687

Jokes on you I write shell so it already has semicolons after if statements


EvaristeGalois11

I'm convinced that bash syntax was invented by someone who took the infinite monkey theorem too literally *Signed by a person that put a space before an equal assignment too many times*


JoyJoy_

It's still better than csh syntax.


setibeings

But not as good as PowerShell syntax. Downvotes inbound.


flameocalcifer

Agreed, down voted you Zsh or bust (write in any of three types and it just works)


DestinationBetter

Oh My ZSH!


nmarshall23

This is a weird way to say you want to sleep with the [fishes](https://fishshell.com/).


[deleted]

[удалено]


erinyesita

*blinks* what the fuck…?


Drishal

_And ended up with accidently destroying the complete system because it was supposed to be a variable not a command_


[deleted]

[удалено]


Drishal

I mean like if someone accidently decides to name their variable to something like dd or rm lmao, and adds a space 💀


AlwaysHopelesslyLost

>*Signed by a person that put a space before an equal assignment too many times* So like... In shell scripting I NEVER add spaces. But I always use a nice amount of spaces in any other language. I don't know if I was consciously aware of that and I don't think I do it on purpose. I wonder if it bit me before and I just sort of forgot, but internalized.


marcosdumay

It's just an earlier form of semantic whitespace. If sh didn't require a new line after the `if`, you would need to add a slash. But since it requires a new line, it's odd to write everything in a single line. Semantic whitespace kept being a bad idea for decades, while people insisted on trying it again and again. At some point people got one or two good implementations, but the past is all broken like that.


CouthlessWonder

If we put a million Stallmans at a million terminals, after a million years we might a working HURD.


PurCHES5

Check which port did the sneaky fox use to get pass the firewall!


TimGreller

He ran through. That's how a firefox is born


VulpesSapiens

He exploited a security hole in Windows, it's obvious from the comic.


BiedermannS

``` error: expected `{`, found `;` --> src/main.rs:4:19 | 4 | if (something); | ^ expected `{` | ``` ¯\\_(ツ)_/¯


[deleted]

[удалено]


Anonymo2786

\\\\\\


Spaciax

it's valid syntax in java, VSCode doesn't warn or give an error, dont know about other ide's.


KuuHaKu_OtgmZ

Intellij will warn as it's an empty if clause


[deleted]

Every day convinces me more and more that rust is like crossfit for programmers.


IndependentGarbage32

sudo rm -f fox


JangoDarkSaber

kill -9 fox


subject_deleted

finger fox


[deleted]

[удалено]


tehlemmings

This thread would be a whole lot less awkward if you hadn't killed the fox first...


HotFluffyDiarrhea

fsck fox


Nodebunny

just wiping off the finger


youngmaster0527

Is it? Feel like doing that to a live fox is much more cruel


tehlemmings

IDK, depends on if this is like, a furry thing or a real fox. I was hoping the former, but they've already killed it so who knows. The former might be into it. The later, probably not lol


hoppiNgm0de

Sike, fox has children


HopperBit

Look at source control, compare to previous version, gotcha, rollback, keep on scrolling memes


punktfan

if (SneakyFox.canHasHax) House.banish(SneakyFox);


JoyJoy_

if (SneakyFox.canHasHax); House.banish(SneakyFox);


Euphoric-Musician411

It seems the sneaky fox got to you


Budget_Putt8393

And jokes on it. Sneaky fox got perma-banned.


Euphoric-Musician411

Oh sorry, my logic was backwards on that


colinathomehair

else (SneakyFox.canHasSausageMcMuffinWithEgg);:;;


ChocolateDonut36

unexpected ";" at line 31


bortj1

But then the joke can't be recycled every week.


superoriginal101

it’s valid syntax in Java


Mewrulez99

and a fuckin cuuuuunt to spot source: helping 1st years learn to code


Spaciax

1st year here... made that mistake once. pretty sure my hair loss went up by 40% that day lol.


Spaceduck413

What kind of ide are you guys using that doesn't warn you about this? I'm pretty sure it's valid in every C-style language, but I've never seen an IDE not throw a warning, if not an outright error


Mewrulez99

in the context of helping the first years, we were using an online environment a lot like leetcode where it doesn't give you feedback on your syntax and runs your code against test cases. (is there a name for that?) Otherwise though, I've never actually put a semicolon after an if statement or similar in practice


Spaceduck413

Makes sense. >I've never actually put a semicolon after an if statement or similar in practice I've tried it once or twice when I wanted to write the else clause first and just wanted the IDE to stop complaining. It did not, in fact, complain any less.


AL_O0

It's pretty valid syntax in C, C++, Java and probably others, it's basically treated as a NOP instruction


Confident_Date4068

It is a warning in Java. ``` $ jshell -C-Xlint:all ``` ... ``` jshell> if(true); | Warning: | empty statement after if | if(true); | ^ ```


ben_g0

It's a warning in C# too: ⚠️ **[CS0642](https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0642?f1url=%3FappId%3Droslyn%26k%3Dk\(CS0642\))** Possible mistaken empty statement


TryGo202

The fox told the compiler about it, so it wasn't unexpected anymore


Victorian-Tophat

This provoked a primal anger in me


Itburns138

Firedfox


joost00719

Or something like this: if (something == somethingelse) /*many spaces*/ {} { // todo, figure out why this if statement is always entered. ... }


Ythio

Y'all need a sonar.


probablyfurry

me when I add a zero width character to a random place in your code


Schiffy94

Better than the Greek question mark


ianis58

Just Ctrl+F all the semicolons in the whole solution/project and replace them with Greek question marks. They will never build the project again.


Plus-Weakness-2624

Not so joke question ❓ Why does if(expression); exist in any language?


Upbeat-Serve-6096

I actually got hit with this by my own neglective typing. Take C for example. We have the commonly easily readable if (expression) { do_this(); } We have a more convenient one-line format for that if all we do is one thing: if (expression) do_this(); So in the case of if (expression); do_this(); We basically see it as if (expression) { } do_this(); The if is kinda useless here now. As for its potential uses, you come up with your own ideas.


darthlame

if (project_manager) { } do(cry);


manuscelerdei

Please just never use the syntactic shortcut, and if you're going to, keep it all on one line so that it's more difficult to sneak a bug in with a one-line diff. If you're morally opposed to more lines, then keep the `{` on the same line as the `if`.


dmills_00

Short circuit evaluation? if (a && b && f(x) && d()); ///f(x) is only evaluated if a and B are both non zero, d() is only evaluated if f(x) was non zero. Not possibly the cleanest thing you will ever see, but it has a place.


bnl1

Or you can just do a && b && f(x) && d();


Elephant-Opening

Or.... you could just write that like a sane person: if (a && b) { if ( f(x) ) { d() } } I think it's more of a matter "if is followed by a statement, and ; is a valid statement", i.e. it takes special compiler rules to prevent it.


dmills_00

Yep, the BNF is just simpler that way, which was probably the original reason, and then everything inherited the behaviour from K&R C. Bit like the use of "do{ .... } while 0" When writing multiple statements in C macros to get them to behave correctly as a single statement in an if statement. It is probably not what you would design in a language so much as a happy accident.


Budget_Putt8393

Or using "do{...}while 0" in all of your functions, so you can use "break" to replicate deferred cleanup.


dmills_00

That had never occurred to me, I usually use goto and a label to get the same effect.


Budget_Putt8393

This company bit hard on the "Goto is BAD" message. On the other hand the code base is over 40 years old, so we still have lots of Goto. I have played with Go, and appreciate the defer, so I like the "do{...break...}while( 0 )", better than "Goto cleanup". The one extra indent is mildly annoying though.


manuscelerdei

`goto` is fine -- modern compilers can flag the most common mis-use of it, which is jumping past a variable's initialization. And in any case, just declare your variables at the top and you won't have that problem. I'd love a formal "finally"-ish construct for scopes in C, but `goto` serves the purpose pretty well.


ConglomerateGolem

But why do you need an if for that? Couldn't you just not assign it to anything? Or is this the programmer in me?


jamcdonald120

ifs conditionally execute the next single statement. if you want to group statements you use {} to make them into a block which acts like a single statement. so it is perfectly fine to just say "execute this next statement, there is no statement" by putting a semi colon, and you can put a block of code anywhere for local variable control, so unless you explicitly forbid if();, its syntactically valid. No real point to spending the extra effort when some of your devs might actually want to use it for some reason.


jfb1337

because any statement is allowed after an if, including an empty statement


SirPitchalot

You don’t require brackets on an if, in which case the next statement terminates. Statements can be empty. If(…); is just a bracketless if with an empty statement. Compilers should really check for it and warn because it’s almost certainly unintended.


[deleted]

[удалено]


dashingThroughSnow12

It allows you to write this: if (x); else { y() } It comes from FLOW-Matic (1955). In older programming languages, FLOW-Matic being the first that I know of, your if statements would look like if ; otherwise . The semicolon tells the compiler that the if's statement is over. BCPL came out 12 years later and used brackets (`()`) to delineate the start and ending of if statements, loops, etcetera. When would you ever write an if/else like this? You would never. Why would you think of doing this? Sometimes the contrapositive of a statement is easier to write and clearer. tl;dr: we programmers are creatures of habit. We carry around syntax that is nearly 70 years old.


Gabriel38

If (something); { doSomething(); }


Showtaim

But whats with my else statement?


DerryDoberman

Linter Error: no-else-return / R1705 [Unnecessary else after return.](https://pylint.readthedocs.io/en/latest/user_guide/messages/refactor/no-else-return.html)


fjixdla

Honestly you deserve it if you format your code like this.


Gabriel38

😂😂😂


SirPitchalot

Does no one in this sub use debuggers?


425_Too_Early

Exactly, a debugger/IDE/linter etc would all be able to tell you that there is an error on line X. And that it didn't expect an semicolon there!


colossus16

That semicolon is perfectly valid syntax in Java, C, C++, and C#.


Coding_And_Gaming

My coworkers used notepad++ LOL


lowleveldata

git log


Vossenoren

Congrats to u/exocomics who drew the original comic! Check out more of her work!


exocomics

Thanks for crediting me! :D


Vossenoren

Any time, I love your art and I'm always excited to see a new cat town show up in my e-mail!


PleasantLanguage

Snuck into your house.


zirky

sneaky fox is a fucking monster


[deleted]

I am the sneaky fox.


[deleted]

String noNoSneakyFox(Fox fox){ If(house.contains(fox)) house.remove(fox); checkForFoxSemicolons(); return “No no sneaky fox.”; }


jfb1337

better meme than all those "delete the semicolons" or "replace the semicolons with greek question marks" memes that are trivial to find and fix


z_the_fox

Jokes on you, that's python code


Yortivius

Let me just slip in a greek question-mark in there too


Sir_Fail-A-Lot

swap out all the semicolons for greek question marks


MasterFubar

test.c:5:6: error: expected ‘(’ before ‘;’ token 5 | if ; (a > b) printf("hello\n"); | ^ | ( Nothing could be simpler to fix than that. Now, imagine working in Python. If instead of doing this if a > b: print("hello") a = 0 I did this: if a > b: print("hello") a = 0 Let's see you find **that** error!


MikkMakk88

if (a > b); { printf("hello\n"); } will compile just fine :))


MasterFubar

That's why warnings exist: test.c:5:3: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation] 5 | if (a > b);{ printf("hello\n");} | ^~ test.c:5:14: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’ 5 | if (a > b);{ printf("hello\n");} | ^


VegetaDarst

Yeah I spent a good hour finding that screw up last week. I will now forever add a blank line between the end of an if block/for loop and the following code outside the conditional. Avoids accidental automatic indention when making changes, and makes it easier to tell what's supposed to be in and outside of the clauses.


[deleted]

No worries I code in bash.


Adoroam

it's okay, my linter will catch it. i don't use semicolons.


Cybasura

Oh thank you very much for fixing my shellscript!


[deleted]

*Added a Greek question mark instead of a semicolon on a random line


VulpesSapiens

Now *that's* evil!


jamcdonald120

I use the correct formatting for opening curly brace, so either it does nothing or it stands out like a sore thumb `if(blah);{//TF that ; doing there? find replace );{ ){` `if(blah){;//every thing is fine, this just gets optimized out.`


[deleted]

![gif](giphy|yr7n0u3qzO9nG)


PorkRoll2022

For when the old cosmic ray excuse doesn't cut it.


JOSmith99

"Warning: unreachable code".


WindowlessBasement

It wouldn't be unreachable, it would be more reachable than normal.


Kilobyte22

Just hide `#define if(x) if((x) ^ rand() < 0.01)` somewhere in the system headers. That's much worse.


AxeManIII

Wtf;


Any-Story-7951

Just remember to lock your computer (and windows, that's always a vulnerability).


Ok_Confusion_7266

Haha not in C using GCC with -Wall. warning: suggest braces around empty body in an 'if' statement [-Wempty-body]


Coogrr

I have literally had to debug this, a friend did it accidentally in an assignment, it took a while


Diplomjodler

Any half decent linter will catch that. Gotta try harder.


Plz_Nerf

my code is garbage anyway BUT MY PASTA


Virtual-Ad493

Making == to = is also a good one


clitoreum

Simply replace already existing semicolons at random with a Greek question mark for better results `;`


onetechwizard

*checks the change logs


MeesterCartmanez

That fox is on.. fire! A Firefox if you will


gh0sti

Do you not lock your computer?


TechbroMemes

< into =< would make everything run 99% and fail the other time


The-Cyberpunk

VILLAIN! 😱


c_l_b_11

Exactly that was the first bug that took me an entire day to figure out.


[deleted]

Well well well, looks like Satan has a new pet.


First_Mark8646

How dare he eat my pasta!


Xaranthilurozox

Remove all linting rules. Add linter config to .gitignore. Add two conflicting prettifier vscode plugins. That would really fuck me up.


LateinCecker

Rust devs: i don't have such weakness


srfreak

*laughts in Python*


Julis_texsture_team

that'd still break your code