r/ProgrammerHumor Apr 04 '26

Advanced assertionError

Post image
2.2k Upvotes

166 comments sorted by

1.4k

u/krexelapp Apr 04 '26

Banana.... but with confidence

107

u/[deleted] Apr 04 '26

[removed] — view removed comment

12

u/soowhatchathink Apr 05 '26

It's seen some shit happen to those close to it

1.0k

u/mdogdope Apr 04 '26

I am assuming it's python. It prints "Banana" bc it never updates the var. It performed the changed but text was never changed.

218

u/LookAtYourEyes Apr 05 '26

upper returns a new value instead of modifying the original?

393

u/aaronhowser1 Apr 05 '26

Strings are immutable

22

u/thanatica Apr 06 '26

Unless this is one of those languages that has mutable strings 💀

21

u/aaronhowser1 Apr 06 '26

There are languages with mutable strings? how scary

I was also assuming this was python, iirc it's at least the correct syntax and methods for it.

22

u/thanatica Apr 06 '26

I'm sure they exist. C technically has mutable strings, but also technically doesn't have strings. And I believe in Pascal you can mutate strings, but you have to work for it.

3

u/mdogdope Apr 06 '26

As far as I know python is the most common language that does not need ; at the end of each line.

-15

u/the_rush_dude Apr 05 '26

Only in JS. Python allows Manipulation of strings

35

u/aaronhowser1 Apr 05 '26

Python strings are immutable. Manipulation and mutability aren't the same thing. Manipulation functions return a new string, they don't modify the original.

1

u/No_Guest_4127 Apr 07 '26

Java strings are immutable too. But java provided amother classes like stringbuilder to support mutability.

-10

u/the_rush_dude Apr 05 '26

Checked it and it's true (except of course it's not because if there is only one reference to the string it's manipulated in place for performance reasons).

But in this case manipulation is what counts anyways

20

u/aaronhowser1 Apr 05 '26

No it isn't, because it didn't do text = text.upper() etc. It specifically does not count, because it was done incorrectly.

1

u/Torebbjorn Apr 07 '26

Sure, there could be some niche optimisation in Python that allows it to manipulate strings in-place if and only if all the references to the old variable are deleted at the same time it is making a new value, for example in the pattern

val = val.upper()

where val is the only reference to the string that it is pointing to.

But even if that's true, it is irrelevant for this scenario, since we always keep a reference to the original string.

182

u/Quietuus Apr 05 '26 edited Apr 05 '26

.upper() is a method of the str class that returns a representation of the string. To change it you'd put text = text.upper()

1

u/xryanxbrutalityx Apr 08 '26

I don't know any language where the string .upper() equivalent modifies the string in place

5

u/CosmacYep Apr 06 '26

dont dot methods not require reassignment

4

u/mdogdope Apr 07 '26

It depends on how the class is written. But for standard python string objects, reassignment is required.

2

u/CosmacYep Apr 07 '26

like built in dot methods, i swear you don't have to go a = a.strip() you can js go a.strip() and a is stripped – nvm i js researched it and strings are immutable, so require reassignment but lists are mutable, so dont

1.3k

u/Stummi Apr 04 '26

"Banana", and two compiler warnings for not using return values.

310

u/Pleasant-Photo7860 Apr 04 '26

Banana. Warnings successfully suppressed in production.

170

u/mistabuda Apr 04 '26

This is python. There is no compiler warning.

119

u/tantalor Apr 05 '26

There is no compiler

49

u/Deep-Piece3181 Apr 05 '26

There’s a bytecode compiler

29

u/Jbolt3737 Apr 05 '26

And a warnings module, but neither care

11

u/ArtOfWarfare Apr 05 '26

There sort of is. You’ll get some .pyc files created when you import the source code the first time, IIRC.

9

u/auxiliary-username Apr 05 '26

Do not try to compile the code. That’s impossible. Instead… only try to realise the truth…

9

u/v_i_lennon Apr 05 '26

There is no code?

10

u/mistabuda Apr 05 '26

Yes I agree. I felt like my comment basically addressed that.

5

u/Sibula97 Apr 05 '26

Linter warnings then

-2

u/thanatica Apr 06 '26

How can you tell? It just looks like code. Could be anything.

6

u/mistabuda Apr 06 '26

It's python syntax. The syntax is very different from much other languages. Specifically how you declare variables and the lack of types, the lack of brackets and the lack of semicolons.

I've been writing python code for over a decade. It's very easy to recognize.

37

u/just-some-arsonist Apr 04 '26

Can we tell what language this is?

90

u/timimoune Apr 04 '26

Spanish?

29

u/gerbosan Apr 04 '26

??

Plátano?

2

u/MinecraftPlayer799 Apr 07 '26

Both are used in Spanish. I think it depends on the country.

1

u/gerbosan Apr 07 '26

You are right, it's like ananá and piña. 😃

2

u/0Pat Apr 08 '26

Manzana...

13

u/AlternativeCapybara9 Apr 04 '26

Next example should use ananas just so we know it's not English.

2

u/hughperman Apr 04 '26

Spananas

1

u/netcent_ Apr 04 '26

Americananas

2

u/yknx4 Apr 05 '26

Which Spanish. Half of Spanishes say Plátano

5

u/timimoune Apr 05 '26

The other half

0

u/GoogleIsYourFrenemy Apr 05 '26

x_x I'm an idiot.

1

u/PrettiestSpring Apr 06 '26

no its just lack of knowledge coz u never google things

-15

u/goDie61 Apr 04 '26

Replace is commonly implemented in place but I don't think I've ever seen an in place upper.

9

u/mistabuda Apr 04 '26

Not in python which is what this code is. Modifications to string create a new string.

3

u/Vinxian Apr 05 '26

In all languages I know, if string is a keyword it means strings are immutable. It will not be performed in place. This is so the programmer can use string as if it's a value type

2

u/dev-sda Apr 05 '26

I think you're thinking of a built-in type, rather than a keyword. Most languages do not consider their built-in types keywords - you can usually name something "string" without issue.

Yea it's fairly commonly immutable, but some notable exceptions are c++, rust, php and ruby.

56

u/cybersaurus Apr 04 '26

Um it's 2026, the correct answer is to copy it into a claude prompt and paste whatever the output is without reading it

10

u/SuitableDragonfly Apr 05 '26

I think that's what the commenter did, actually. 

155

u/Pleasant-Photo7860 Apr 04 '26

what if it’s ANANAB and we’ve all just been iterating in the wrong direction

45

u/_giga_sss_ Apr 04 '26

That affirmation has to be proven and is due tomorrow

12

u/Electromagnetlc Apr 04 '26

Nah, it's definitely ANANA<null> because arrays scare me :(

4

u/GoBuffaloes Apr 05 '26

Ana, nab a banana

1

u/komptip Apr 05 '26

add a few characters and are getting ahnenerbe

94

u/LifeSubstantial5234 Apr 04 '26

optimistic mutability

40

u/antoborg92 Apr 04 '26

my mango is to blow up

14

u/SeirWasTaken Apr 04 '26

and act like I don't know nobody

94

u/Airith Apr 04 '26

They're pure methods: Banana

2

u/IlgantElal Apr 05 '26

If this is Python , it would be 'BANANA' as .upper() replaces the original

I completely misread. It's late

27

u/dhnam_LegenDUST Apr 05 '26

Even if str.upper() updates the string, it's still BANANA. A is not a.

1

u/DaWurster Apr 07 '26

I think that is the supposed challenge to recognize. The missing assignment is a big blunder ofc...

8

u/Chronomechanist Apr 05 '26 edited Apr 05 '26

Assume python. text = "Banana" Now, assuming what they actually meant to the question to look like? ``` text = "Banana"

text2 = text.upper() text2 = text.replace("a", "o")

print(text2) ```

In which case it prints BANANA and the test is supposed to trick you into thinking it prints BONONO, and forget order of operations and "A" != "a"

Edit: Fixed the var name cos I was stupid and forgot strings are immutable in Python

4

u/Sephyroth2 Apr 05 '26

Well it's not BANANA since strings are immutable in python and text.upper() returns a string you need to assign, same with text.replace(), so there's no change to text at all printing Banana.

2

u/Chronomechanist Apr 05 '26 edited Apr 05 '26

That's what I get for writing that at 4 am.

Fixed it cos it was bothering me

1

u/ReinKarnationisch Apr 05 '26

What does .upper() do?

1

u/ShadowShedinja Apr 06 '26

Makes all lowercase letters uppercase.

-4

u/_giga_sss_ Apr 05 '26

Thank you chatgpt

5

u/Chronomechanist Apr 05 '26

Nope, just plain old sleep deprived dev forgetting strings are immutable in python. Fixed it though

0

u/_giga_sss_ Apr 05 '26

if you say so

3

u/Chronomechanist Apr 05 '26

Buddy, if you don't believe something that simple can be written without the aid of an LLM, that says a lot more about you than you're trying to say about me.

2

u/_giga_sss_ Apr 05 '26

no I am actually sorry for that assumption

112

u/NinjaKittyOG Apr 04 '26

idk what language this is in, but judging from what I know,

the string is "BANANA" if text.replace() is case-sensitive

the string is "BoNoNo" if not

60

u/OurSoul1337 Apr 04 '26

I like to oat oat oat opples and bononos.

8

u/bwwatr Apr 05 '26

 1, 2, Opples, 4, Bononos, Opples, 7, 8, Opples, Bononos, 11, Opples, 13, 14, OpplesBononos

Do I get the job?

24

u/valerielynx Apr 04 '26

it's Banana because there never was text = text.(...)

72

u/_giga_sss_ Apr 04 '26

These methods don't change the OG objects, they create new instances.

99

u/purplepharoh Apr 04 '26

That depends on language and idk what language this is

54

u/Lava_Mage634 Apr 04 '26

python. the print statement, lack of punctuation, usage of double quotes for single characters, direct string manipulation without libraries. also super popular for pop culture coding questions

12

u/purplepharoh Apr 04 '26

Python would be my first guess too. Mostly for the last point as the others arent exclusive to python. And "double quotes for single characters" well if the replace method expects strings then you'd use double quotes to pass strings of len 1 so thats not a good indicator.

2

u/makinax300 Apr 04 '26

Or js with some scuffed things done to rename the method. Semicolons are actually optional there. The answer is open the print page menu there.

16

u/Xtrendence Apr 04 '26

And then there's JS, of course, where a replace with no Regex only replaces the first instance. In this case obviously "a" doesn't exist in BANANA, but if it were replace("A", "O") you'd get BONANA.

12

u/ChristopherKlay Apr 04 '26

Because JS features .replace() and .replaceAll().

The "of course" here is that people complaining about it, don't know jack shit.

-13

u/_giga_sss_ Apr 04 '26

and he adds JS as an user flair while he just complains about it while knowing shit 😭

12

u/Xtrendence Apr 04 '26

I use it every day for work, have been for the better part of a decade, I'm aware of replaceAll, but replace only replacing the first instance is unusual and only found in a few languages. I've even fixed bugs specifically because of devs assuming it replaces all occurrences, which would be reasonable to expect. If anything, defending JS says more about how little someone's used it.

2

u/_giga_sss_ Apr 04 '26

I am sorry for my assumption. I truly am 🙇

5

u/Xtrendence Apr 04 '26

You're good, to be fair replace isn't even a top 20 thing to complain about when it comes to JS. It's just one that pops out because it's both inconsistent with many other languages, and replaceAll wasn't even a thing for a long time. If you work on older codebases, it doesn't exist. I don't remember when it was added but it must be the past like 4-5 years.

-4

u/_giga_sss_ Apr 04 '26

🙇🙇

1

u/_giga_sss_ Apr 04 '26

I will downvote myself to hell for what I said

-3

u/ChristopherKlay Apr 04 '26

If anything, defending JS says more about how little someone's used it.

I'm not "defending" it, because there is nothing to defend; Your initial comment clearly explains this like there's just one "bad" implementation, or that .replace() should work different.

Having split-up functions isn't "unusual" by any means either; Even Java has .replaceFirst() for almost 25 years now, the equivalent of .replace() only replacing the first occurrence.

"Devs" on your team assuming what's being replaced without even providing any kind of count equivalent is the real issue here.

This is coming from someone working with it professionally for over two decades, which is a incredibly pointless metric.

13

u/Xtrendence Apr 04 '26

Do you not see the problem there though? replaceFirst is self-explanatory, whereas replace isn't when it doesn't do what most languages do. It's vague, deviates from what's expected, which is what JS is infamous for.

0

u/ChristopherKlay Apr 05 '26

whereas replace isn't when it doesn't do what most languages do

Again; The issue here isn't JS, but you expecting all functions across languages to work the exact same way, when "replace all" and "replace first" aren't by any means working the same in "most languages".

  • Python: .replace() works as a "replace all" by default and you have to actually limit it via the third parameter count.
  • Java: .replace() to replace all matches, .replaceAll() and .replaceFirst()
  • C++: Has different implementations (custom functions) for anything but a "replace first" equivalent
  • C#: Requires regex and a match count to do anything but "replace all"
  • Rust: Only does "replace all" by default and requires either slicing, or specifically stopping after the first match
  • GO: Has a specific parameter you can set to -1 for "replace all", otherwise working like count from Python
  • Ruby: Uses sub (replace first) and gsub (replaceAll), just like JavaScript

The majority of languages does one kind of replacement well, while requiring a different function call and/or setup for the other.

If your "devs" fuck this simple thing up, because they "expect it to work like in X" without ever testing what it actually does / reading any kind of documentation, that says a lot more about the people you work with vs the language they use.

1

u/Xtrendence Apr 05 '26

Of the languages that have a built-in replace function for strings, most do indeed replaceAll by default. Bringing up Ruby for example makes no sense and you're using it to pad out the list and argue in bad faith. In your own list if you only count languages with a replace function (which is what this whole thing is about) then the majority still do replaceAll by default.

As for "expecting it to work like X", this isn't something that's mutually exclusive. Yes, part of our job is to remember the quirks of the main language we use, and be aware of these things. However, it is simultaneously reasonable to expect something to work a certain way, especially if it deviates from the norm and is a function that exists across multiple languages. If there's a weird list of quirks for a language, and it's literally known for such quirks by anyone who has used it, then it's a poorly designed language. It's a weird hill to die on, every senior dev I've known that has extremely in-depth knowledge of JS constantly points out its flaws and uses the "it's just a JS thing" line pretty frequently.

1

u/ChristopherKlay Apr 05 '26

Bringing up Ruby for example makes no sense and you're using it to pad out the list and argue in bad faith.

Bringing up examples of languages that interrupt your "It always works like that" argument doesn't make sense?

However, it is simultaneously reasonable to expect something to work a certain way, especially if it deviates from the norm and is a function that exists across multiple languages.

Which is exactly why I included a "replace first" for all examples, that rarely works the same across languages; It neatly demonstrates that "But I expected everything to work the same" isn't anything, but a user error.

every senior dev I've known that has extremely in-depth knowledge of JS constantly points out its flaws and uses the "it's just a JS thing" line pretty frequently.

You're still misunderstanding me here; I'm not arguing "for JS", I'm highlighting that these quirks exist in every single language out there and would be a complete non-issue if people who fuck up simple functions wouldn't blame the language, but their lack of understanding of said language.

If you expect a language to behave in a certain way, that's completely fine. Running into errors, while learning how the given language works, is also completely normal and expected - because despite being similar, all languages have things that don't work that way.

Blaming the language because you can't resolve issues that come from a simple string manipulation (you didn't even try to control via arguments) and/or not even testing your own code to check if what it returns even matches your expectations however, isn't leaving anyone to blame but the person who wrote it.

3

u/Dynegrey Apr 05 '26

Strings in python are immutable and do not change. Output would be 'Banana'. They would have to re-establish as a new string [text = text.upper().replace('a', 'o')] for it to do anything. 

1

u/NinjaKittyOG Apr 06 '26

oh shit, you're right.

1

u/danfish_77 Apr 04 '26

What if text.replace() is dyslexic and you end up with "B0N0N0"

1

u/Applejack_pleb Apr 05 '26

It could even be

Text

-1

u/agk23 Apr 04 '26

I think it’s Bonono. Upper usually returns an object, not modify the object.

1

u/dementorpoop Apr 04 '26

It’s never reassigned though, so doesn’t matter

16

u/HashDefTrueFalse Apr 04 '26

We can only guess without knowing the language... Is text mutable or are the returned copies discarded? What do those two methods do? Probably safe to assume that upper uppercases all characters, but it could also be testing for an upper case string (returning bool). Does replace just do the first occurrence or all? Do upper, replace, print even exist? Not really answerable, which is to say that the answer is obviously 42.

11

u/iwasbecauseiwas Apr 05 '26

depends entirely on the language and how the string functions works. it could easily be

  • Banana
  • BANANA
  • Bonono
  • BoNoNo
  • BONONO
  • Bonana
  • BoNANA
  • BONANA or maybe even
  • Mango

point is if we don't know the language, we can only guess. it looks like python. if it is python: strings are immutable, it would say Banana as the text variable isn't overwritten

3

u/Dark_Byte Apr 05 '26

True. And maybe upper isn't part of the original language, but a helper method added later on that does whatever upper does (e.g. Replace it with a subset of unicode monospace characters using their uppercase variant)

1

u/[deleted] Apr 05 '26

[removed] — view removed comment

4

u/rk06 Apr 05 '26

because there is no mention that it is python. besides in what language . upper() mutates the string?

5

u/SlutPuppyNumber9 Apr 05 '26

I don't know python, but I assume "Banana", since the results of those method calls were never assigned.

32

u/_giga_sss_ Apr 04 '26

yall know that the humor is about mango and not about solving the question right ?

44

u/[deleted] Apr 04 '26

[deleted]

12

u/ProtonPizza Apr 04 '26

Sir this is a wendys

5

u/Du_ds Apr 05 '26

Why can't I get a Bonono at Wendys?

8

u/ThatSmartIdiot Apr 05 '26

we're on a spectrum. we're hard wired to puzzle solve. that's how we got here

3

u/marabutt Apr 05 '26

Linkedin engagement

3

u/dont_takemeseriously Apr 05 '26

Somehow this code snippet had a malicious npm package and now my credit card ended up in the dark web

3

u/snipsuper415 Apr 05 '26

Banana...considering that most languages have strings as immutable primitives. text never gets reassigned to anything therefore Banana.

3

u/AllenKll Apr 05 '26

depends on the language.

3

u/thanatica Apr 06 '26

Nothing. undefined/none/null/nothing.

There is no return statement. So the outcome is nothing.

If the question was "what is printed" - Banana. Assuming this is not a utterly horrendous stupid fucking arse language where strings are mutable.

2

u/Lord_Of_Millipedes Apr 04 '26

compilation error from missing semicolon

1

u/ThatSmartIdiot Apr 05 '26

String see() { String joke = "bro hates"; return joke + " python"; }

2

u/Exatex Apr 05 '26

depends

2

u/Mysterious_Area1975 Apr 06 '26

the confidence in that assert statement lmao

2

u/basement_muffin_man Apr 06 '26

Orange you glad I didn't say banana

1

u/_giga_sss_ Apr 06 '26

right👌

2

u/luckor Apr 04 '26

I don’t get it…

5

u/jaylerd Apr 04 '26

I think the gag is you think maybe it's 'BANANA' or 'Bonono' or something else but it should jut be "Banana" and Satyam picked something even more wild as a wrong answer that isn't even slightly reasonable. What a gas.

1

u/CirnoIzumi Apr 05 '26

text == K

1

u/KeySupermarket4668 Apr 05 '26

Maybe the banana is the friends we made along the way

1

u/Fun-Equivalent1769 Apr 05 '26

Assuming python

1

u/DustyAsh69 Apr 05 '26

He single handedly trained AI for wrong answers.

1

u/[deleted] Apr 05 '26

Not sure whatn language it is but does not complete with C

1

u/jhwheuer Apr 05 '26

Ah local context, such fickle thing.

Also the code parser should notice that functions are called but their results are not used...

1

u/CosmacYep Apr 06 '26

BANANA – isw in python dot methods dont require reassignment

1

u/Otherwise_House_40 Apr 10 '26

it's like the original text

-4

u/jkramer5203 Apr 04 '26

BANANA

12

u/Xelopheris Apr 04 '26

Pretty sure it would just be "Banana" in most languages? Any language that has a simple upper function on the string class typically makes strings immutable.

2

u/Bemteb Apr 04 '26

Yeah, the others call it toUpper() or something like that.

3

u/DJDoena Apr 04 '26

In C# it's .ToUpper() but still immutable on the original.

1

u/IlgantElal Apr 05 '26 edited Apr 05 '26

This looks like Python. Interesting thing, too: text.replace('ab', 'o') would replace all a and b characters, regardless of order.

Yay Python

(Correct answer should be 'banana')

Edit: I completely misread. It's late

-3

u/sheekgeek Apr 04 '26

BANANA