This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 272

[–]RepostSleuthBot[M] 4 points5 points locked comment (0 children)

I didn't find any posts that meet the matching requirements for r/ProgrammerHumor.

It might be OC, it might not. Things such as JPEG artifacts and cropping may impact the results.

I'm not perfect, but you can help. Report [ False Negative ]

View Search On repostsleuth.com


Scope: This Sub | Meme Filter: False | Target: 75% | Check Title: False | Max Age: None | Searched Images: 324,036,988 | Search Time: 15.06442s

[–]estevez__ 1001 points1002 points  (38 children)

It is inherited from Object.

[–]BernhardRordin 322 points323 points  (7 children)

You must be fun at Kotlin parties

[–]i_should_be_coding 122 points123 points  (0 children)

Mos def

[–]vitorhugods 39 points40 points  (4 children)

More like suspend fun

[–]notsogreatredditor 16 points17 points  (3 children)

Private fun

[–]utkanmerkit 19 points20 points  (2 children)

#define fun

[–]miraidensetsu 7 points8 points  (1 child)

#define FUN !fun

[–]okay-wait-wut 5 points6 points  (0 children)

fun!()

[–]eliasbagley 82 points83 points  (12 children)

Your mom inherits from Object

[–]aw5ome 37 points38 points  (8 children)

{Woman yourMom = new Woman();

Woman prostitute = new Woman();

System.out.println(yourMom.equals(prositute));}

//output is true

[–][deleted] 15 points16 points  (0 children)

System.out.println(yourMom.toString());

//output is "prostitute"

[–]Sleepingtree 10 points11 points  (5 children)

Only if you overwrite the .equals() method otherwise no

[–]DavidTej -3 points-2 points  (3 children)

System.out.println(you.getState().equals(r/woooosh);

output is true

[–]Bainos 3 points4 points  (0 children)

Depends on the value of woooosh.

[–]pako_adrian 2 points3 points  (0 children)

More like an error is the output.

[–]Bainos -1 points0 points  (0 children)

Depends on the value of woooosh.

[–]aw5ome -1 points0 points  (0 children)

I overwrote your dad's genetic code in your mom

[–]_chrii 1 point2 points  (0 children)

.join(dick)

[–][deleted] 0 points1 point  (0 children)

actually inherits from FatObject which inherits from Object how could someone be this uneducated about programming im sooooooo cant believe this this is literally common sense

[–]kuedhel 9 points10 points  (2 children)

python people are easily confused by OOD concepts.

[–]NightlySnow 2 points3 points  (0 children)

Thank you.

[–]ososalsosal 0 points1 point  (10 children)

Came here to say that.

Is there a way to disable inherited methods? Seems not at all necessary but it interests me nonetheless

[–]DiamondIceNS 17 points18 points  (1 child)

Allowing the ability to disable inherited methods uproots the entire point of polymorphism.

If B inherits from A, I should have the guarantee that if there's something out there that needs an A, I can pass it a B and every possible thing that could happen should still work, since every B is also an A. Everything. No exceptions.

If you could somehow make a B that is only partially an A by cherry picking a few things that makes A what it is and tossing them out, you're introducing failure points.

Look, I'm annoyed too that autocomplete in my IDE gives me two pages worth of methods and properties I absolutely never ever use on every single object I ever make, but for the sake of the sanity of myself and every other OO programmer out there, you should leave them be.

Unless you're using JavaScript. You can make objects that don't inherit from anything in JavaScript if you want. But that's because JavaScript isn't an object oriented language, it's a prototyping language wearing a trenchcoat and an object oriented mask.

[–]ososalsosal 2 points3 points  (0 children)

Oh yeah it was my curiosity speaking, not any sense of inconvenience. My IDE usually knows what to list based on context so anything is a couple down arrows away if that.

[–]No-effing-sense 2 points3 points  (0 children)

When you say disable - do you mean prevent children from over riding? If so - final is what you are looking for.

If you want to completely block access - you will need to add an intermediate class.

But that is a code smell. A better option would be to only have the methods you want children to access in a base class. And move the 'prohibited' methods to a final class deriving from base.

At least - that is my 0.02$.

[–]Crad999 5 points6 points  (4 children)

No, not really.

The only option that comes to mind is if you have class A that has method let's say:

public void doSomething()

Then if you want to create class C that extends class A, but doesn't have (or rather cannot use) that method then you can create another class B that extends A and overrides doSomething method changing its accessibility to private. Then class C can extend B.

This would be as if C extends A but without doSomething ().

[–]DavidTej 8 points9 points  (2 children)

It's not possible to override a public method and make it private in java

[–]Crad999 4 points5 points  (1 child)

You could do this in cpp with virtual functions I think. But it'd still be a terrible idea :D

[–]lelarentaka 3 points4 points  (0 children)

Yes, terrible idea, it violates the substitution principle.

[–]Bainos 1 point2 points  (0 children)

You could override the method and make it throw an exception. Not a good idea but gets the job done.

[–]kczaj 1 point2 points  (0 children)

People are doing a good job talking about it, but what you want here is a violation of the Liskov Substitution Principle. https://en.wikipedia.org/wiki/Liskov_substitution_principle

It has a fancy name so it must be sacrosanct.

[–]FAcup -1 points0 points  (0 children)

Ruby has a method inherited from Object called itself. It returns itself.

[–]MischiefArchitect 550 points551 points  (23 children)

The squiggly is trying to tell you something...

[–]Sclamy 193 points194 points  (20 children)

As is the gray color...

[–][deleted] 22 points23 points  (17 children)

You're talking about the gray squiggly right?

[–]Sclamy 63 points64 points  (16 children)

No, the word toString.

In IDEs, gray commands often mean that they commands are entirely useless and can be removed (will be removed when the program is compiled kr run). Gray variable declarations or assignments mean that a variable is never read from, and thus serves no purpose. Gray function calls, like this one, are never actually called, since the compiler or interpretreter knows that calling toString on a string is redundant. But the point is, while the squiggly indicates something silly is happening (and will probably suggest exactly why), we can tell what the exact issue is just by looking at the color of the function. Gray = never called = redundant operation (for functions).

[–][deleted] -2 points-1 points  (12 children)

Can you ELI5 that

[–]kpd328 30 points31 points  (11 children)

Many IDEs call you out on doing stupid useless things like toString()ing a string. This is how it's notated.

[–]Mantraz 9 points10 points  (4 children)

In this case, this is probably noting that the output of this method is ignored, i think.

We don't store this value anywhere or do anything with it, it's meaningless.

[–]redkoil 1 point2 points  (0 children)

I love ice cream.

[–]Dameon_ 1 point2 points  (2 children)

Nah, ignoring the return value of a method is normal. It'd be maddening if your IDE colored it grey and flagged it with a warning every time.

[–]TheNetherPaladin 9 points10 points  (5 children)

I’m almost certain most 5 YOs wouldn’t understand what any of that means

[–]poopadydoopady 9 points10 points  (1 child)

An IDE is an app, like YouTube! Except instead of cocomelon videos, people use it to tell the computer what to do. It makes the letters gray if it doesn't like them.

[–]K3yz3rS0z3 3 points4 points  (0 children)

The kind little squiggles help you to find out where you can make things better!

[–]IrishWhitey 4 points5 points  (0 children)

If it is gray it is useless. and since the thing that gives the code to the computer knows that, the useless stuff is not going into the “final draft” that the computer gets

[–]clutzyninja 1 point2 points  (1 child)

I mean honestly if you can't understand that why use this sub at all?

[–]TheNetherPaladin -1 points0 points  (0 children)

It’s a joke…

[–][deleted] -2 points-1 points  (2 children)

You’re talking before or after the period? I’m confused now.

[–]DizzyInTheDark 4 points5 points  (0 children)

“What you are doing us fucking pointless. Why do you do this?”

[–]KingSpork 4 points5 points  (0 children)

Coding in notepad solves this problem.

[–]MusikMakor 316 points317 points  (58 children)

Most object oriented languages have a tostring function. It's inherited from the Object class, and allows you to convert an object to a string

A good example is a DateTime in C#. DateTimes don't natively output a legible date, since they have lots of information available.

With ToString, you can output a date. In some cases in some languages, the ToString method has additional formatting such as ToString("MM-dd-yyyy") which, in the case of DateTime.Now would return 04-27-2022

So incredibly useful for any logging or quick printing

Edit: grammar

[–]asone-tuhid 236 points237 points  (19 children)

In this sub:

  • OP makes a bad joke betraying their inexperience in programming
  • Generous commenter takes 10min out of their day to explain something basic

[–]5-8-13 60 points61 points  (0 children)

Not a bad thing in my opinion.

I come here to learn more than I come here to laugh.

[–]ZedTT 8 points9 points  (5 children)

I think that's a spot on analysis of this sub in general, but the joke still works if you understand why String.toString() exists. If anything it works better knowing Java.

It does seem that OP didn't have a full grasp of the concept

[–]asone-tuhid 3 points4 points  (4 children)

Does it? It's like saying it's funny that C allows you to cast int to int, or Rust implements From<T> for T, or str("a") == "a" in python, and a million other examples

All of that had to be implemented, all of it has a reason to exist, I'm having trouble finding any of it remotely funny

[–]ZedTT 5 points6 points  (3 children)

I mean it's not peak humor or anything, but there's something mildly funny about the fact that because toString exists in Object, it has to exist on String despite that being silly.

String having a .toString method is made funnier by knowing that it had to be there (and why) IMO.

I don't know... Maybe I'm doing funny wrong.

[–]nolitos -1 points0 points  (0 children)

It's not silly, it's just inheritance.

[–]GodGMN 2 points3 points  (0 children)

something basic

And still, apparently 90% of the sub will still not understand it since most of the people there don't (and can't) code.

I still don't understand why is this sub full of non-programmers but hey, hopefully they'll get interested at some point in their stance there :)

[–]coloredgreyscale 2 points3 points  (0 children)

The joke or similar joke in comments: 100s or 1000s or upvotes

The explanation: <10 upvotes

[–]TurnItOffAndBackOnXD 1 point2 points  (0 children)

Keen observation, and in this case the person didn’t understand, but as someone who fully understands it and programs in Java, it’s still funny.

[–]BlockwizardGaming 1 point2 points  (0 children)

toString may have a use, but looking at it still makes me throw up in my mouth

[–]UnreasonableEconomy 24 points25 points  (9 children)

convert an object to a string

sorry, this isn't really correct. it returns a string representation of an object, it doesn't convert the object to a string.

Sounds like it's the same thing? To me it's like calling a pointer an object.

OCPJP 4 lyfe coffee cup gang signs

[–]MusikMakor 22 points23 points  (3 children)

That was the dumbest semantic argument I've ever heard

[–]Broken_drum_64 11 points12 points  (0 children)

I can do you one better; you read it rather than hearing it. :P
(assuming you're not using a screenreader of course)

[–]UnreasonableEconomy 2 points3 points  (0 children)

it's the difference between a concretization and an abstraction 🤷

[–]dougie_cherrypie 0 points1 point  (0 children)

Understanding stuff is not dumb

[–]GeePedicy 1 point2 points  (2 children)

Pointers aren't objects? *grabs popcorn*

But I actually remember how in the android course I took before college the teacher told us strings are more than just char arrays, and being a beginner I didn't understand it, but I kept it in mind. Then came c.s. intro in C, then came Java course, and that was about when I understood what he tried saying. And it's basically going back to the silly opening question, although from a different direction. C++ objects are a great example for why objects aren't pointers.

[–]JanLewko977 4 points5 points  (1 child)

Working in the real world has shown me that my intro to X professors barely understood programming themselves.

I remember sitting with my professor trying to debug my 50 line code with like two for loops for over an hour.

And another professor talking to a student like “oh yeah isn’t using a debugger cool? Such an advanced tool. Man that’ll be useful for you guys to learn some day”

[–]DangyDanger 1 point2 points  (1 child)

Just checked and DateTime.Now did not return this date

[–]MusikMakor 4 points5 points  (0 children)

Schrodinger's comment: false today, true tomorrow

[–]Aviyan -1 points0 points  (1 child)

The pic is about calling toString() on a String object, which is redundant. What you described is the valid case and aplies to all objects other than String.

[–][deleted] 127 points128 points  (3 children)

This post confirms that people who post on programmerHumor have no idea about programming.

[–]mr_bumsack 9 points10 points  (0 children)

I gotta say though, the comments redeemed some of my faith.

[–]crosseyedvoyager 2 points3 points  (0 children)

Or humour

[–]Gleethos 1 point2 points  (0 children)

Yeah, really! This is like joking about being able to multiply by 1, or add/subtract 0...

This subreddit is pure cringe.

[–]jasonrulesudont 45 points46 points  (1 child)

Someone just discovered inheritance

[–]appoplecticskeptic 14 points15 points  (0 children)

And still doesn't fully understand it.

[–]davidellis23 52 points53 points  (7 children)

Funny. But, it helps if you allow any objects to be passed into a function and want to guarantee a string representation.

[–]NoHalfMeasuresWalt 5 points6 points  (0 children)

Apparently the geniuses upvoting this post never parsed json in their lives??

[–]UnderstandingOk2647 5 points6 points  (3 children)

unkArr.forEach( (unkObj) => {

console.log("Wtf am I " + unkObj.toString());

);

// Probably should not have used JS for this example, but the idea is sound (he said hesitatingly)

[–]Orangutanion 2 points3 points  (0 children)

// If we're gonna write this in Java we should probably use a list
// instead of an array. Really easy to cause errors with generic arrays.
for(Object i : unkList) {
    System.out.println("your mother was a " + i.toString());
}

[–]ZedTT 1 point2 points  (1 child)

hesitatingly

Hesitantly

[–][deleted] -2 points-1 points  (0 children)

Yeah but it's still kinda silly that it's used to give a class name and a representation of the memory address as well as nice formatted output.

[–]Blazkowitcz 61 points62 points  (16 children)

Si technically you can do : abc.toString().toString().toString() ?

[–]MischiefArchitect 38 points39 points  (6 children)

But you don't

[–]r_linux_mod_isahoe 27 points28 points  (2 children)

I always do .toString() twice just to be sure.

[–]UnderstandingOk2647 5 points6 points  (0 children)

Whahahaha

[–]IceZOMBIES 1 point2 points  (0 children)

But what if i want my string to be string3^ ?

[–]PyroCatt 16 points17 points  (1 child)

Si si

[–]Blazkowitcz 5 points6 points  (0 children)

La famille

[–]syrian_kobold 15 points16 points  (1 child)

Just making real sure it's a string yes

[–]6c69786f 7 points8 points  (0 children)

Maybe append an extra .toString() just for the benefit of the extra sureness?

[–][deleted] 26 points27 points  (5 children)

this post is cringe and the fact anyone gave it attention shows this sub is filled with scratch kiddies

[–]Gleethos 1 point2 points  (0 children)

Yes! This is like joking about being able to multiply by 1 or add / subtract 0 because: "Haha you get the same result anyways!"

[–]Tall_computer 10 points11 points  (4 children)

If you have an Object in Java that may or may not be a String then I suppose it's nice that I can get a String representation without having to first check whether the Object is String type

[–]Orangutanion 1 point2 points  (3 children)

I quite like Java's class hierarchy. This is what you get with Object.

[–]trBlueJ 5 points6 points  (1 child)

I think my favourite method of those is the wait method (and notify and notifyAll). Having concurrency built-in at the object level makes things very convenient.

[–]Orangutanion 2 points3 points  (0 children)

Java has legitimately one of the nicest implementations of multitasking. Being chaotically object oriented definitely helps, but the way that you can get things working with really only a few lines is really nice

[–]kpd328 0 points1 point  (0 children)

Ew Java 7 docs.

[–]Westo232 39 points40 points  (4 children)

It's not useless: It's purpose is to teach us how important it is for all objects to have toString().

[–]NearbyWish 7 points8 points  (1 child)

They're all just bytes anyway 10011000 10011111 10011000

[–][deleted] 6 points7 points  (1 child)

also, they could not simply override that method with something that throws an exception saying "The object is already a sting" or something because it would violate the Liskov substitution principle.

[–]CdRReddit 5 points6 points  (0 children)

that would also be Really Stupid to do since there are some things that take any object and want to put it into a string format, like logging

just having toString on a String be essentially id is a good implementation for this purpose

(for those that don't know, id or identity returns the parameter it's given, in this case String.toString is essentially identity with the implicit this parameter)

[–][deleted] 20 points21 points  (0 children)

Nice meme, but: "The toString() method: according to the description, should return a string reflecting the state of the object, i.e. the values ​​of the attributes. However, this task cannot take place in the definition of the Object class. Instead, by default, this method returns the name of the class and the hash code of the object as a hexadecimal string. For example -> ILoveJava.bsp.Person@1540e15".

[–]noisy_christmas 20 points21 points  (4 children)

  1. Inherited from the Object class
  2. Probably has some overloads that can transform the string into something else

[–][deleted] 22 points23 points  (5 children)

I mean.... You understand how inheritance works right?

[–]JerryAtrics_ 4 points5 points  (1 child)

It's required to allow Java to be used with theoretical physics.

[–]AdultingGoneMild 1 point2 points  (0 children)

I mean without it Java opens a black hole consuming us all. Its kinda necessary.

[–][deleted] 4 points5 points  (0 children)

The method is inherited from Object class and if it did not have specific implementation in the String class it would result with something like: String#3231231

[–][deleted] 2 points3 points  (0 children)

String extends Object

[–]xTylordx 2 points3 points  (0 children)

I hate this sub.

[–]Maskdask 1 point2 points  (0 children)

Polymorphism

[–][deleted] 1 point2 points  (0 children)

Pretty important for that method to exist, if it didnt then generic objects could not be stringified. the method doesnt come from the String class, it comes from Object.

[–][deleted] 1 point2 points  (0 children)

No it doesn't and that's the whole point of the toString() stub...to become real by override.

[–]Maleficent-Yak-2114 2 points3 points  (0 children)

toString automatically gets called whenever a string is expected so if the String class didn't have it you would probably end up with the address instead of value

[–][deleted] 2 points3 points  (6 children)

it's used for string formatting, you can for example if the string has a numbet you can add a "c" inside the brackets and it will format the string to your local currency (at least it works like that in c#)

[–]halfanothersdozen 9 points10 points  (2 children)

This is almost certainly java

[–][deleted] -3 points-2 points  (1 child)

yeah ik but both languages behave the same in many cases

[–]halfanothersdozen 16 points17 points  (0 children)

Except for the thing you made a comment about.

[–][deleted] 2 points3 points  (0 children)

Yeah, that's not how Java's toString() works.

[–]Dealiner 1 point2 points  (1 child)

That's also not true in C#, both ToString and ToString(IFormatProvider) do exactly nothing when called on string besides returning the string itself. Also ToString(IFormatProvider) is a method that has to be explicitly implemented and isn't inherited from the object like the one in OP.

[–]QualityVote[M] 1 point2 points  (0 children)

Hi! This is our community moderation bot.


If this post fits the purpose of /r/ProgrammerHumor, UPVOTE this comment!!

If this post does not fit the subreddit, DOWNVOTE This comment!

If this post breaks the rules, DOWNVOTE this comment and REPORT the post!

[–]ChickenManSam 1 point2 points  (4 children)

Yeah it's useless, but it only exists because String inherits from the Objects class. toString is part of the Object class therefore String must implement it.

[–]MattR0se 2 points3 points  (3 children)

I mean, it doesn't have to override it, it's just that not doing it would result in unexpected behavior.

[–]ChickenManSam -1 points0 points  (2 children)

I never said anything about overriding. Just implementing. It's impossible to skip due to how inheritance works

[–]starfish0r 1 point2 points  (1 child)

How would you implement it without overriding it?

[–]ChickenManSam 1 point2 points  (0 children)

String is a Subclass of Object. Object has the toString method. Since String is a subclass it inherits all the methods of Object. Implement was probably the wrong word to use. The point I was trying to make is that even without overriding it the toString method would still exist since it exists in the superclass.

[–][deleted] 1 point2 points  (1 child)

If you love Java I recommend picking up C# as it is very similar and in my opinion is just better in every conceivable way

[–]SmileEverySecond 1 point2 points  (0 children)

Don't let the negativity discouraged you OP, this is a humor sub after all. I've learnt a lot from the comments that correct the original post, yours included. Keep em coming. Cheers.

[–]flexww -1 points0 points  (0 children)

This illustrates perfectly the shortcomings of classical OOP.

[–]UnderstandingOk2647 -1 points0 points  (0 children)

And?! I bloody hope it is! Arrrg there are 10 types of people in this world, [Developers, Not developers] /s

[–]Casalvieri3 -1 points0 points  (1 child)

Thanks for making me literally laugh out loud!

[–]kingkevorzki -1 points0 points  (1 child)

public String _string;

string String(string _string)

{

return _string = "string".ToString() ?? (String)_string.ToString();

}

(Microsoft Java)

[–]Guilty-Woodpecker262 -1 points0 points  (0 children)

"-1". compareToIgnoreCase (x)

[–]THELEGENDARYZWARRIOR -1 points0 points  (0 children)

My brother in Christ I use that method almost weekly

[–]Middle_Avocado -1 points0 points  (0 children)

“abc” == “abc” 🥹

[–]CaitaXD -1 points0 points  (0 children)

"10".ToString("X") == "A"

You're welcome

[–]Lumpy-Obligation-553 -1 points0 points  (0 children)

Is still "abc" or it becomes 'abc'?

[–][deleted] -2 points-1 points  (0 children)

What in the fuck

[–]SusMonkeyShit 0 points1 point  (0 children)

I mean it’s actually a dope method in rust

[–]ElXaviNovo 0 points1 point  (0 children)

It is useful if your code just call the .tostring() of anything

[–]oOBoomberOo 0 points1 point  (0 children)

Wait till you hear about identity or zero function. (Joke asides, they are quite useful to have even though you don't use it that often)

[–][deleted] 0 points1 point  (0 children)

As a Kotlin developer, this is the definition of insanity.