Skip to main content
GameDev.net gamedev.net
🔒 Locked

A super bad designs to avoid

Started by Nicholas Kong May 7, 2013 at 7:42 AM 4 replies 4.2k views
Original Post
Nicholas Kong
Nicholas Kong

So I wrote this for my second project for Data Structures. The method chaining got out of control and I violated so many rules of encapsulation.

I have 2 years with general programming experience so how could I gone wrong? Well, I was so focused on getting the features of the program to work. Once I understood how the features was suppose to work, i just hop on my seat and started typing.

Behold my code:

// reduce exponent by one for all exponents greater than 1
Main.getPolynomialHolder().get(polynomialIndex).getPolynomialVector().get(i).setExponent(Main.getPolynomialHolder().get(polynomialIndex).getPolynomialVector().get(i).getExponent()-1);
Yeah...not pretty one bit. I am gonna get a failing grade for this...*virtual smack on forehead*
Let this be a lesson to all newcomers on what not to do. This issue is actually scattered in multiple lines of code. Aw man I am doomed.
ZebraQuake
ZebraQuake

You could have at least kept the property as it's own variable, haha.


//This is really pretty
Polynomial banana = Main.getPolynomialHolder().get(polynomialIndex).getPolynomialVector().get(i);
banana.setExponent(banana.getExponent() - 1);
Nicholas Kong
Nicholas Kong


You could have at least kept the property as it's own variable, haha.


//This is really pretty
Polynomial banana = Main.getPolynomialHolder().get(polynomialIndex).getPolynomialVector().get(i);
banana.setExponent(banana.getExponent() - 1);

Yeah that could have been more readable. Someone on this forum once quoted saying at most you should do is " a.b() " which is a good quote.

21st Century Moose
21st Century Moose


You could have at least kept the property as it's own variable, haha.


//This is really pretty
Polynomial banana = Main.getPolynomialHolder().get(polynomialIndex).getPolynomialVector().get(i);
banana.setExponent(banana.getExponent() - 1);

This of course depends on whether or not the various "get"s have other side-effects and the code relies on them being called twice......

shudder

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
gautamn15
gautamn15

I have seen a lot of people do something like that in production code just to be extra smart. Sadly for being extra smart you generally get a bunch of crashes and bugs which someone else will have to fix.

TheChubu
TheChubu

Doing more than 3 or 4 "concatenated" method calls always makes me doubt if what I'm doing is right.

But then, making a single do-all method call makes you think if that method does more than it should :D

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"   My journals: dustArtemis ECS framework and 

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.