|
2007 best coding practices
Last post 10-16-2007 3:40 PM by ammoQ. 19 replies.
-
10-15-2007 3:52 PM
|
|
-
Kilwch


- Joined on 05-15-2006
- Posts 18
|
2007 best coding practices
The team I belong to is managing some activities like support, framework developpement. Support include pro-active support, like giving best practices and auditing some random applications to see if they are straightforward designed or WTF.
- This one is supposed to be a convenience to know if a String is "null or zero" : the dev hopped it returned true if the argument was null, zero-length or containing only "00000....". Comments are mine.
private boolean isNullOrZero(String aString) { boolean b = true; //let's see later the use for this one... aString = aString.trim(); //Now aString is trimed so remember it is clean and safe to use ! if (aString == null) { //Dead code. If it was true, a NPEx would have been raised the line before ;p return true; } if (aString.trim().length() == 0) {//Re-trimming aString to be sure. return true; } int i = 0; while (i < aString.trim().length()) {//Triming each loop to be REALLY sure ! if (aString.trim().charAt(i) != '0') { //Wait... can't remember if aString is trimed... return false; } i++; //Damn ! this "while" loop is strangely close to a "for"... } return b; //Now we can use the boolean initialized to true at the begining }
- Some dev just can't get the point with MVC, especially controllers and Spring framework. Despite strong messages to discourage the use of instance attributes in controllers, they did so. So a few applications passed Quality Testing because it is done by 1 user a time, but crashed the first morning on production...
|
|
-
-
WeatherGod


- Joined on 04-19-2006
- Posts 279
|
Re: 2007 best coding practices
Wait, thare are jobs like that? Do the clients ever listen to the suggestions? As for the code piece, I don't know what else to be said. You seemed to capture all of my thoughts in your comments. I am curious to see what their "corrected" version looks like.
|
|
-
-
rbowes


- Joined on 02-09-2007
- Winnipeg, MB
- Posts 412
|
Re: 2007 best coding practices
I can take a guess how this evolved. It started with a line that was just "aString.trim()" which, of course, didn't work. So they added .trim() everywhere to fix it. Then somebody else came by and noticed the "aString.trim()" alone, and fixed it to "aString = aString.trim()". Voila!
|
|
-
-
belgariontheking


- Joined on 08-20-2007
- Cincinnati, OH, USA
- Posts 2,276
|
This has nothing to do with the post, but I'm trying to figure out whether WeatherGod's icon is pro- or anti-Linux. A simple answer will do, as opposed to a flamewar.
SpectateSwamp exposing aliens. Obviously the World needs SSDS
[10:07] <fatdog> so from now on.. be sure to wear nice clean underwear [10:07] <mps> fatdog: That is simply not going to happen
|
|
-
-
ammoQ


- Joined on 04-13-2005
- Vienna.Austria.Europe.Earth
- Posts 3,445
|
belgariontheking:This has nothing to do with the post, but I'm trying to figure out whether WeatherGod's icon is pro- or anti-Linux. A simple answer will do, as opposed to a flamewar.
Most likely anti-Linux. Read some of his other posts.
beanbag girl 4ever
|
|
-
-
Spectre


- Joined on 05-09-2007
- ::1
- Posts 771
|
Re: 2007 best coding practices
Kilwch://Now we can use the boolean initialized to true at the begining
Mwa-ha-ha! Now this is where I really LMAO-ed. Y'know is could be used as a performance optimization technique. Just put:
boolean true_value = true;
boolean false_value = false;
at the top of your files, so you won't have to recreate the values every time.
╩юфют√ь ёЄЁрэшЎрь яюЁр эр яхэёш■.
#TDWTF @ SlashNET was merged into #codelove @ the same network. You're still welcome to drop by. I guess.
|
|
-
-
skippy


- Joined on 03-10-2006
- Calgary, AB
- Posts 188
|
Re: 2007 best coding practices
Take the overuse of "trim" in the while/for loop and change that to an equivalent redundant database lookup, and that's a lot of the code I had to fix to "improve performance". Granted the DB lookup was hidden behind a C++ object, but the programmer(s) knew that.
|
|
-
-
WeatherGod


- Joined on 04-19-2006
- Posts 279
|
belgariontheking:This has nothing to do with the post, but I'm trying to figure out whether WeatherGod's icon is pro- or anti-Linux. A simple answer will do, as opposed to a flamewar.
It is supposed to be Pro-Linux. I really can't think of any comments that I have made that would indicate that I am anti-Linux. I am Pro-Linux, Pro-Mac all the way. I just have no artistic skill whatsoever.
|
|
-
-
broekage


- Joined on 06-29-2007
- Posts 16
|
Re: 2007 best coding practices
private boolean isNullOrZero(String aString) {
return aString == null || aString.trim().matches("0*");
}
Should do quite nicely. I mean, is this stuff really that hard!?
|
|
-
-
ammoQ


- Joined on 04-13-2005
- Vienna.Austria.Europe.Earth
- Posts 3,445
|
WeatherGod: belgariontheking:
This has nothing to do with the post, but I'm trying to figure out whether WeatherGod's icon is pro- or anti-Linux. A simple answer will do, as opposed to a flamewar.
It is supposed to be Pro-Linux. I really can't think of any comments that I have made that would indicate that I am anti-Linux. I am Pro-Linux, Pro-Mac all the way. I just have no artistic skill whatsoever.
I think this one sounds rather anti-Linux, but maybe I've missed your point.
beanbag girl 4ever
|
|
-
-
aihtdikh


- Joined on 02-07-2006
- Posts 51
|
WeatherGod: belgariontheking:This has nothing to do with the post, but I'm trying to figure out whether WeatherGod's icon is pro- or anti-Linux. A simple answer will do, as opposed to a flamewar.
It is supposed to be Pro-Linux. I really can't think of any comments that I have made that would indicate that I am anti-Linux. I am Pro-Linux, Pro-Mac all the way. I just have no artistic skill whatsoever.
That reminds me of this comic strip. I hadn't seen that one for quite a while.
|
|
-
-
joe.edwards


- Joined on 08-14-2006
- Dallas, TX
- Posts 249
|
ammoQ: WeatherGod: belgariontheking:
This has nothing to do with the post, but I'm trying to figure out whether WeatherGod's icon is pro- or anti-Linux. A simple answer will do, as opposed to a flamewar.
It is supposed to be Pro-Linux. I really can't think of any comments that I have made that would indicate that I am anti-Linux. I am Pro-Linux, Pro-Mac all the way. I just have no artistic skill whatsoever.
I think this one sounds rather anti-Linux, but maybe I've missed your point.
That particular quote seems clearly pro-Linux. Think of it in the light that all software has limitations, but closed-source software forces you to live with them where open-source software encourages you to fix them (and share your fix with the community).
Windows Vista has been deliberately crippled in the name of Digital Rights Management. Community driven software would never impose such things on you.
|
|
-
-
Erick


- Joined on 08-18-2006
- South Carolina
- Posts 46
|
Re: 2007 best coding practices
Well the problem with this code is quite obvious. He should have been using aString.IsVeryTrim()
|
|
-
-
shadowman


- Joined on 07-27-2006
- Maryland, USA
- Posts 463
|
joe.edwards@imaginuity.com: ammoQ: WeatherGod: belgariontheking:
This has nothing to do with the post, but I'm trying to figure out whether WeatherGod's icon is pro- or anti-Linux. A simple answer will do, as opposed to a flamewar.
It is supposed to be Pro-Linux. I really can't think of any comments that I have made that would indicate that I am anti-Linux. I am Pro-Linux, Pro-Mac all the way. I just have no artistic skill whatsoever.
I think this one sounds rather anti-Linux, but maybe I've missed your point.
That particular quote seems clearly pro-Linux. Think of it in the light that all software has limitations, but closed-source software forces you to live with them where open-source software encourages you to fix them (and share your fix with the community).
Windows Vista has been deliberately crippled in the name of Digital Rights Management. Community driven software would never impose such things on you.
The relevant part of the quote was Isn't Linux's philosophy "Please work around any
technical limitations in the software"? Perhaps he meant what you are talking about, but the confusion here is because "Work around" != "Fix". I'm sure Weather God is thrilled we're resorting to dissecting his forum posts like they're a high school literature assignment. :-)
|
|
-
-
ammoQ


- Joined on 04-13-2005
- Vienna.Austria.Europe.Earth
- Posts 3,445
|
shadowman:Perhaps he meant what you are talking about, but the confusion here is because "Work around" != "Fix".
That's how I understood the post.
beanbag girl 4ever
|
|
-
-
m0ffx


- Joined on 08-15-2006
- Posts 602
|
It is a bit ambiguous. Anti-LInux because it's saying one should pay to get a good OS? Or pro-Linux because it's saying Linux will cost you less than a quarter?
TRWTF is Community Server
|
|
-
-
WeatherGod


- Joined on 04-19-2006
- Posts 279
|
shadowman: joe.edwards@imaginuity.com: ammoQ: WeatherGod: belgariontheking:
This has nothing to do with the post, but I'm trying to figure out whether WeatherGod's icon is pro- or anti-Linux. A simple answer will do, as opposed to a flamewar.
It is supposed to be Pro-Linux. I really can't think of any comments that I have made that would indicate that I am anti-Linux. I am Pro-Linux, Pro-Mac all the way. I just have no artistic skill whatsoever.
I think this one sounds rather anti-Linux, but maybe I've missed your point.
That particular quote seems clearly pro-Linux. Think of it in the light that all software has limitations, but closed-source software forces you to live with them where open-source software encourages you to fix them (and share your fix with the community).
Windows Vista has been deliberately crippled in the name of Digital Rights Management. Community driven software would never impose such things on you.
The relevant part of the quote was Isn't Linux's philosophy "Please work around any
technical limitations in the software"? Perhaps he meant what you are talking about, but the confusion here is because "Work around" != "Fix". I'm sure Weather God is thrilled we're resorting to dissecting his forum posts like they're a high school literature assignment. :-)
Ok, I can see how that can be interpreated as anti-Linux. I really didn't expect this level of attention here. I will make it clear... I said "Work around" because that was the wording used in the OP of that thread. Joe.Edwards's statement reflects what I meant by that statement. In addition, my icon was inspired by the Dilbert comic mentioned above. Can we now focus back on the OP's WTF?!
|
|
-
-
pitchingchris


- Joined on 04-30-2007
- Louisville, KY
- Posts 385
|
Re: 2007 best coding practices
Now wait a minute, I wanted 0.0...
|
|
-
-
asuffield


- Joined on 05-31-2006
- Posts 2,137
|
WeatherGod:Can we now focus back on the OP's WTF?!
No. We have to obsess on this for a couple more pages first.
|
|
-
-
ammoQ


- Joined on 04-13-2005
- Vienna.Austria.Europe.Earth
- Posts 3,445
|
asuffield: WeatherGod:Can we now focus back on the OP's WTF?!
No. We have to obsess on this for a couple more pages first.
Plus start two or three new threads about that topic, spread among the forums. But of course that doesn't put an end to the old thread.
beanbag girl 4ever
|
|
Page 1 of 1 (20 items)
|
|
|