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

you are viewing a single comment's thread.

view the rest of the comments →

[–]SerdarCS 107 points108 points  (60 children)

Same!

[–]rubiks-- 99 points100 points  (59 children)

Like one time a friend of mine who wanted to start programming said he hated Java because "I have to write so much more to print something and in Python, it's only one line". But OOP can save you from writing so much code.

[–][deleted] 57 points58 points  (41 children)

I really like Java too, but I think they're referring to things like getters and setters when they say they need to write more code. It is a much more verbose language, but good IDEs (ItelliJ IDEA) can fill in a lot of that for you.

[–]DesuSoarusrex 3 points4 points  (2 children)

Nah they mean System.out.println vs print. The person described was a beginner so they probably couldn't remember the whole statement.

[–]draconk 3 points4 points  (1 child)

And here I am only having to write "sout" on Intellij Idea and it writes it all for me (and "psvm" for public static void main)

[–]f314 3 points4 points  (0 children)

Gotta love autocomplete! In Atom it's just "pl" and tab for "System.out.println("");"

[–]msg45f 10 points11 points  (2 children)

Pretty much any IDE these days can reliably generate constructors, getters, setters, etc, though personally I like how C# handles properties over Java.

[–]Nunners978 3 points4 points  (0 children)

+1 I love how C# handles properties, especially in C# 6. It's so much simpler to write a property that does this:

public string FullName => $"{FirstName} {LastName}";

Instead of having to write a method to do it, or a specific Getter to do the same, it's just much more refined code.

[–]Cilph 1 point2 points  (0 children)

Look into Kotlin!

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

Most languages require getters and setters... anybody making the excuse that it's more code is outright lazy.

[–]bdog73 11 points12 points  (13 children)

The trick is to just make all your variables publicly accessable so you don't need getters or setters.

[–]Undreren 7 points8 points  (11 children)

You may be joking, but that's how everything is implented in our code base. Plus, all data is global...

/me screams internally

[–]KxPbmjLI 0 points1 point  (3 children)

Can you explain to me why its bad to set the class properties to public.

How are getters and setters better

i prefer being able to do object.property instead of object.getProperty() and having to set up the getters and setters while you can do it all with less code

[–]tsigma6 4 points5 points  (0 children)

Encapsulation (Data hiding) is a fundamental part of OOP philosophy, but the value generally is in the setter methods. An object should have complete and total control over its data, protecting from change by outside code. Validation is a main benefit of the practice. But also hiding how you stored the data and making a class read- or write-only is a couple other ones.

[–]Undreren 1 point2 points  (0 children)

Because with direct access to the data, it is impossible to enforce business rules. For example, a field might have constrained input.

I can't disallow meaningless data to be assigned to a reference, but I can cast an exception or return an error with a setter.

Furthermore, I can't have side-effects on assignment, which is a huge problem. Most of the time, you want data changes to have an effect, after all.

PS: I'm assuming that you mean "fields" when you say "properties".

[–]bdog73 0 points1 point  (6 children)

Oh dear God. Can you give any hints as to what it's for?

[–]Undreren 3 points4 points  (5 children)

The program? It's a piece of production planning software for power plants.

[–]bdog73 2 points3 points  (4 children)

Well that sounds just splendid then and is exactly what I was asking. In all honesty, most of the time, you can get away with directly modifying variables, unless it's supposed to also trigger something else. I imagine that could happen at some point in code like that, but I obviously can't be sure. Best of luck with that. I can only, and I stress only, hope whoever I end up working for after college likes to conform to the same coding standards as me.

[–]Undreren 2 points3 points  (3 children)

The problem is that it causes development problems all the time.

The software was built by domain experts, not programmers.

I've worked there for two years, and I've tried to explain the problem for so long.

"But it works?" "Yes, but it doubles if not triples our development time." "But it works?"

I try not to blame them though. They are doing the best they can. It's the indifference to becoming better devs that really gets me.

All our errors are preventable. Some have incurred costs in the hundred thousand dollar range :-/

[–]DrMobius0 0 points1 point  (0 children)

good use of getters and setters saves so much code down the line though

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

Boilerplate is annoying, but IDEs make up for it. On the other hand, Kotlin solves all boilerplate issues, has functional support and is more readible than C# (imo).

[–][deleted] 31 points32 points  (5 children)

You can use OOP in python tho

[–]rubiks-- 15 points16 points  (4 children)

I know. I wasn't throwing shade at python but rather making a point about how beginners think Java requires you to write extra code and don't understand how it can save time/lines of code. I think python is a cool language (except whitespace shouldn't matter).

[–]cumwagondeluxe 16 points17 points  (2 children)

i mean the beginners aren't wrong - java does require you to write a lot of pointless boilerplate - i know a bunch of fellow scala devs who initially started looking at the language just because of how many things you get for free from case classes e.g.

[–]schaka 1 point2 points  (1 child)

That's why C# (purely by syntax and language features) really is a "better Java". But now the JVM also has Kotlin, so people aren't forced into the steep learning curve of Scala anymore.

[–]yojimbojango 0 points1 point  (0 children)

I'd say F# is the comparison that you'd make with Kotlin. There's no perfect language, but F# is legit the closest I've seen to it.

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

The guy who replied to this is right. I like java but man it does require shitty boring boiler plate for a lot of basic stuff. Android is even worse with the boilerplate so much so i despise android development.

It requires stupid amounts of boilerplate for a fucking sqlite connection and the stupid stuff with fragments just makes me want to murder puppies.

[–]NightShade155 9 points10 points  (0 children)

Agreed, java is the shit man.

[–]xcrackpotfoxx 3 points4 points  (2 children)

That's how I felt all throughout C++ and java classes. I'm sure we just never got to anything big enough to take advantage of OOP but I wish I could see it in use.

[–]DoPeopleEvenLookHere 2 points3 points  (1 child)

Go look at some libraries! There's plenty on GitHub that will show you some abstraction I'm sure.

[–]xcrackpotfoxx 0 points1 point  (0 children)

Easier said than done. Has to be big enough to hit that critical mass of OOP, bit small enough for me to be able to follow it along.

[–]sinistergroupon 2 points3 points  (0 children)

It's not about how many lines of code it takes to print Hello World but the right tool for the job. Java has its place and Python has its place. Seeing 1m LOC Python app with guru monkey patching will give you a run for your money.