Jump to content

  • Log In with Google      Sign In   
  • Create Account

A super bad designs to avoid

  • You cannot reply to this topic
5 replies to this topic

#1 warnexus   Prime Members   -  Reputation: 1505

Like
0Likes
Like

Posted 07 May 2013 - 01:42 AM

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.

Edited by warnexus, 07 May 2013 - 01:43 AM.


Sponsor:

#2 ZebraQuake   Members   -  Reputation: 131

Like
0Likes
Like

Posted 07 May 2013 - 10:03 AM

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);


#3 warnexus   Prime Members   -  Reputation: 1505

Like
0Likes
Like

Posted 07 May 2013 - 11:19 AM

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.



#4 mhagain   Crossbones+   -  Reputation: 8285

Like
1Likes
Like

Posted 07 May 2013 - 03:36 PM

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


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#5 gautamn15   Members   -  Reputation: 116

Like
0Likes
Like

Posted 20 May 2013 - 01:00 AM

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. 



#6 TheChubu   Crossbones+   -  Reputation: 4819

Like
0Likes
Like

Posted 20 May 2013 - 01:51 AM

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 Making a Terrain Generator






PARTNERS