|
Great, and sadly (for us that deal with bad programmers), very funny.
|
|
|
|
|
I like stuff like this - how will you ever know what is right if you don't know what is wrong
|
|
|
|
|
Good explanations, Really i missed this one since it was posted on Feb month. Have my 5
|
|
|
|
|
this is the way how the British ppls are.
|
|
|
|
|
..you must surely mean superior to the Bangladeshis at Cricket?
|
|
|
|
|
Liked it a lot, very good explanations
Some really serious stuff for some serious guys!!!
It seems I am becoming too serious
|
|
|
|
|
Thanks, glad you liked it! Ali
|
|
|
|
|
The most fundamental mistake is to choose an appropriate programming language for the problam domain. For example when the majority of your programming involves lots of string manipulation then COBOL 74 should be the language of choice.
|
|
|
|
|
I couldn't help but recall that quip while reading your article. And it's no less truer today than it was back some twenty-plus years ago when one of my friends stated it to me.
|
|
|
|
|
So true! And something that I don't think all programmers fully appreciate! Ali
|
|
|
|
|
...is my favorite.
Develop a big System of Code, and surround every 10th line with stuff like:
Private Sub LoadData()
Try
Me.OrdersTableAdapter.Fill(Me.OrdersDataSet.Orders)
Me.OrderDetailTableAdapter.Fill(Me.OrdersDataSet.OrderDetail)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
So User can click away the Message, and Application can go on (for to crash elsewhere, with corrupt data).
But debugging also is fun: "Which of my 50 TryCatches is now popping up there?"
Do you have enemies, or competitors under your collegues?
While they are out for coffee, place in their files stuff like the following brilliant:
Private Sub LoadData()
Try
Me.OrdersTableAdapter.Fill(Me.OrdersDataSet.Orders)
Me.OrderDetailTableAdapter.Fill(Me.OrdersDataSet.OrderDetail)
Catch ex As Exception
End Try
End Sub
That will give you a significant lead over them.
|
|
|
|
|
Mr.PoorEnglish wrote: 'go on, brother - don't worry, be happy!
Ali
|
|
|
|
|
Perhaps the greatest incentive for Rule #4 is that lengthy code suggests great effort! Of course, greater effort is required for succinct code, but try explaining that to management! Or worse, explain that to the customer, who believes they are paying more for less! So be verbose and cash in.
|
|
|
|
|
Yes, its amazing how many people equate quantity of code with quality of code!
Ali
|
|
|
|
|
You can change the article name with How protect your code or a kind of Manual obfuscator .
Indeed a great article, it must be bookmarked immediately!!
|
|
|
|
|
Many Thanks! Ali
|
|
|
|
|
You forgot Needless Repetition.
Back in the days of Fortran 4 (so bear in mind this was all GOTOs and CONTINUEs), I came across a block of code that went something like this:
if (condition_A)
var1 = function1(parameter set 1)
if (condition_B)
var1 = function1(parameter set 2)
if (condition_A)
var2 = function2(parameter set 1)
if (condition_B)
var2 = function2(parameter set 2)
if (condition_A)
var3 = function3(parameter set 1)
if (condition_B)
var3 = function3(parameter set 2)
...
...
for about 12 different functions.
It took me quite a while to figure out and convince myself that exactly the same test was was being done each and every time.
Even I thought that was a bit much, and like you I'm an engineer, not a professional programmer.
Nice article, it would be funny if it wasn't true.
|
|
|
|
|
Repetition is always good, there is nothing more fun when reviewing your code than having to wade through many lines of virtually identical code. In fact you can turn it into a game of 'spot the difference'! Ali
|
|
|
|
|
From Stephen Brooks, a friend of mine... @ http://www.stephenbrooks.org/[^]....
There are rather more I can think of (mainly because I've done some of
them):
- [me] Use characters outside the standard ASCII set like degree or square
(superscript 2)
- [Something I've seen others do] don't use the memory manager when you can
just make a fixed array with 10000*10000 entries, that should be big enough
for anything!
- [me] Handle exceptions like this
if (11==sscanf(str," %d %d %g %g %g %g %g %g %g %g %g",
&pn,&pid,&ke,&wt,&x,&y,&z,&vx,&vy,&vz,&t))
{
...
}
else {printf("Error bad mallards\n"); getchar();}
- [me] Make comments only decipherable if you know specific people by name,
e.g.
for (sign=0;sign<2;sign++) for (useful=0;useful<2;useful++) for
(i=0;i<=20;i++)
{ // Double-binned stuff that Roger was going on about
for (j=0;j<=20;j++) pizp[sign][useful][i][j]=0;
for (j=0;j<36;j++) pizth[sign][useful][i][j]=0;
}
- [me] Use the conditional ternary operator on Lvalues, e.g.
*(sign?&gminus:&gplus)+=gwt; *(sign?&gminusvar:&gplusvar)+=gwt*gwt;
- [others] Limit all function names to 6 characters or less, in all-caps.
Then make a handy paper index where you can look up what PR09CF does
- [me, now corrected] Make variable assignments inside short-circuited logic
statements, so you don't know whether they have been initialised or not
float x,y;
if (fabs(x=ax-bx)<50 && fabs(y=ay-by)<50) {...}
// Now try to use y!
- Make a global but then pass it as an argument to a function *anyway*
- Write code that relies on the fact "int a,b;" puts a and b in adjacent
memory slots, e.g. memset(&a,0x00,8);
- [me] Create a really long structure containing multiple types and then
initialise it all in-line, e.g.
} ops={"config.txt", 0,180,-1, 0, 1,0, COMMANDLINE, -1, 0, 1,100,
"auto.sav", 0,0,0,0, 0,
"results.dat","results.txt", {3,6,1,"Mpts"}, {"queue.txt",NULL,0,0,5,0},
100000,50,10000,10,
1,24,12,NULL,'L', 0,0,0,0,0, NULL,-1, "ftp -s:script.ftp",0,0,
NULL,"Unknown","",
NULL,0, 0, "none", 0,100, NORMAL_PRIORITY_CLASS,THREAD_PRIORITY_NORMAL,
50<<20,0.5,NULL,'B'};
Very readable!
- On Hungarian notation,
double *dwString;
|
|
|
|
|
Michael Adams wrote: Use characters outside the standard ASCII set like degree or square
This is just evil!
Michael Adams wrote: Create a really long structure containing multiple types and then
initialise it all in-line, e.g.
} ops={"config.txt", 0,180,-1, 0, 1,0, COMMANDLINE, -1, 0, 1,100,
"auto.sav", 0,0,0,0, 0,
"results.dat","results.txt", {3,6,1,"Mpts"}, {"queue.txt",NULL,0,0,5,0},
100000,50,10000,10,
1,24,12,NULL,'L', 0,0,0,0,0, NULL,-1, "ftp -s:script.ftp",0,0,
NULL,"Unknown","",
NULL,0, 0, "none", 0,100, NORMAL_PRIORITY_CLASS,THREAD_PRIORITY_NORMAL,
50<<20,0.5,NULL,'B'};
And this is even more evil! Ali
|
|
|
|
|
Shoot him an email sometime on his website or Yahoo: he's very particular about which sites he uses.
|
|
|
|
|
Did you ever teach this in a class? I’ve inherited 3 projects that I swear the programmers followed these rules to the letter.
|
|
|
|
|
Eeerrr, as a matter of fact ....... No, those programmers can take all the credit for the quality of their projects! Ali
|
|
|
|
|
Never free the memory you allocate. There is a lot of memory in today's computers.
Always let there be bugs in your code. This will make the customer be interested for the next fixed version.
Always put C and assembly code in C++ projects. This will make others understand that you are multilingual.kostas KEL
|
|
|
|
|
Three more excellent points! Ali
|
|
|
|
|