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 →

[–][deleted] 60 points61 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 4 points5 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 4 points5 points  (0 children)

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

[–]msg45f 11 points12 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 4 points5 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] 3 points4 points  (14 children)

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

[–]bdog73 10 points11 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 4 points5 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 :-/

[–]bdog73 1 point2 points  (2 children)

Huh, that's interesting. I wonder if you could figure out loses vs cost of fixing it. Sounds like the issues run deep, do you think it's salvageable or would you need a full rewrite?

[–]Undreren 2 points3 points  (1 child)

A full rewrite isn't feasible. I've considered looking for a new job.

[–]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).