r/Python • • Jan 05 '18

Really??

Post image
2.0k Upvotes

317 comments sorted by

View all comments

Show parent comments

2

u/scootstah Jan 08 '18

Uncomplete example for brevity. Perhaps I gave you too much credit to figure it out.

class Example
{
    public static string foo = "bar";
}

Example.foo;

1

u/[deleted] Jan 08 '18

You only showed yourself ignorant. What happens when Example is unloaded from memory?

Globals in Python stick around until the end of the process.

2

u/scootstah Jan 08 '18

It won't get unloaded so long as references linger.

Regardless, globals are bad, and a strong code smell. If your only complaint with Java is that it doesn't properly support a terrible feature, then I guess you don't have any valid issues.

1

u/[deleted] Jan 09 '18

globals are bad, and a strong code smell. ... terrible feature ...

I disagree. I use globals all the time to share global state between code. If Python had dynamic variables, I'd use them too.

In a way, Java classes themselves are globals. Sacrilege, I know.

EDIT: By the way, are you going to yield the point and agree with me that Java does not have globals?

2

u/scootstah Jan 09 '18

I use globals all the time

I see. Well, I hope you enjoy working on your untestable and bug-prone software. Hopefully some day you learn to do it the right way.

By the way, are you going to yield the point and agree with me that Java does not have globals?

No, because I just shared with you a way to use globals in Java.

1

u/[deleted] Jan 09 '18

But they're not globals. They disappear when references are lost. Globals don't do that.

And you can totally test globals. I do it all the time. Any function that has a side effect is basically doing the same thing as a function that modifies a global.

2

u/scootstah Jan 09 '18

But they're not globals. They disappear when references are lost. Globals don't do that.

It has the same effect. If you're no longer holding reference to something, why does it need to still exist?

I could link you three dozen articles explaining why globals are a code smell, but I'll let you look it up yourself.

In the mean time, we can agree to disagree.

1

u/[deleted] Jan 09 '18

It doesn't change the fact that they're not globals. You don't need to maintain references to globals to keep them existing.

And it is something that Java doesn't do, code smell or not.

Just pack it in --- you've lost this one. I showed you something that Python can do that Java cannot.

2

u/scootstah Jan 09 '18

I guess you'll just have to get out of your box and learn to code the correct way.

1

u/[deleted] Jan 09 '18

Sorry, you're picking on the wrong guy. I've got several years of Java and Python and several other languages under my belt.

Just admit defeat, admit that Python can do things that Java can't, and move on with your life. It's OK to be wrong.

→ More replies (0)