Message Board


Message Board > Programming > Robust programming

July 8, 2012, 18:16
Zomg
None
641 posts
Today I'm doing the Blogpost assignment (make a blogger app) and I got stuck wondering what Types of objects should be in my app and what responsibilities they should have.

I would like to share with all of you, this interesting conversation I had with a few advanced developers:

------
you wanna separate everything so that each component becomes small and easy to understand

a class should perhaps only communicate with the database or update the user interface or represent a Person or handle other classes, etc

you should override equals, hashCode and toString

and inheritance should be used if and only if there is an is-a relationship between the classes

Vehicle > Car > ConvertibleCar

and you can in best case test different parts independently

your goal is to have a big system where you have tests for the components

If you repeat code you're doing it wrong. If you need an if statement or ?: (and not because of some API forcing you to) you're doing it wrong.

if you repeat code you might introduce inconcistencies and you'd have to copy paste a lot… extract it to a method/class, etc and you're good to reuse a component which is proven to work

you should have a human understandable representation
not the default class hashcode thin

Also, try to minimise mutable state. Not particularly an OO maxim, but one that makes sense.

yes make things private final

local scoped

volatile is for mutable things.
transient

don't use a static SimpleDateFormat...
it's not thread safe

and remember months start with 0=January

Calendar/Date is hell

Days of the week should be an ordered group with no 'first'.

How does one decide which responsibilites a class should have and should not have?
It should have one responsibility.

common sense/real life comparison usually decides it, if you have a CarPark and a Car the method to stop and start the car's engine wouldn't be in CarPark, it would be in Car

I mean you could very easily write some kind of CarPark.Spaces[3].StartEngine()
but that would be bad

just because the property exists it doesn't mean it has to be populated

as long as you write your view code to deal with empty titles for example

well only you know your domain :)
------
____________
#
July 9, 2012, 11:23
Dennis
どこかにいる
2092 posts

The fun part about university is, you learn how things SHOULD be done. When you graduate, you see the most horrific abominations, making you wonder how anyone who graduated could have done that...

The best part is: you aren't even allowed to change it. You just have to modify 10 different components all over the software and maintain it that way.

The reason is it takes too much time (and money) for your employer to change this.

It's frustrating. I was scolded once for spending 3 days on something that should only take 3 hours and I said: but the programming code was not transparant enough so I improved it! The business employer said: "But you spend too much time/money on trying to make it better, also creating bigger impact on dependant interfaces and resources"...

They aren't programmers so they don't know anything about it. YOU are capable of making great programs. THEY decide to spend money on it, so you're stuck with a shitty system anyway...



Everyone has different reactions to this shit:

- some people pull all their hair out
- some people laugh histerically and jump through a window out of the absurdness
- some people die without reason after hearing it. Reason: BRAIN DAMAGE
- some people just smile and laugh and make jokes of it with collegues and try to make the best of it :P


I recommend the last option!
____________
Kwakkel
#
July 9, 2012, 23:11
PB
Defender of the faith
630 posts

It's a good thing to know the strengths of different programming languages. For instance, some statements you make seem verry specific to Java.

Quoting Zomg:
a class should perhaps only communicate with the database or update the user interface or represent a Person or handle other classes, etc

Basically: learn the design patterns

Quoting Zomg:
If you need an if statement or ?: (and not because of some API forcing you to) you're doing it wrong.

In my opinion, you are allowed to use if statements.
I'd even use inline if statements in specific scenario's. I think I'd first question myself:
- Is there a chance this code will be changed later, when maintained?
- Will this line be readable to other developers?
- Will this line of code remain short enough to quickly interpret when reading it?

[Edited on July 9, 2012 by PB]
____________
#

Message Board > Programming > Robust programming

Quick reply


You must log in or register to post.
Copyright © 2005 Booleansoup.com
Questions? Comments? Bug reports? Contact us!