|
To be fair to the project managers etc, the software development "profession" hasn't exactly covered itself in glory.
It's undetstandable why they assume that software is always going to be buggy and therefore quick fixes should be prioritised over this nebulous notion of "good code".
Be honest, if you picked a company at random and looked at their source code for internal apps, would you "expect" to find good code or bad?
The overwhelming majority of code in the world is bad bad bad.
As a profession we're still living in caves and drawing crude pictures of animals.
There are signs that things are improving. The Ugg family in Cave 7 are playing with Test Driven Development. The Oggs in Cave 8 have this thing called Refactoring. The Flintstones over in Bedrock have been using something called Design Patterns.
We're on a slow upward climb towards being a real profession but we won't get there doign the things we've done in the past.
It should take as long to become a software developer as it does to become a doctor, and we should probably be choosing specialties in much the same way. Sadly you can become a "programmer" with less training than a Burger Flipper.
-Richard
|
|
|
|
|
All true, but that's several more reasons to try to at least advance to the bronze age. Why, of all things, should I work in a profession when I don't care about it or my skills at all?
Richard, too
A while ago he asked me what he should have printed on my business cards. I said 'Wizard'.
I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.
|
|
|
|
|
> Why, of all things, should I work in a profession when I
> don't care about it or my skills at all?
Oh, you should definitely care about your skills and the profession, that's not what I'm saying at all.
What I'm saying is that it might not be easy to get the "right way" message accross.
You may find that it's better to seek out the people who are building software the right way, rather than try to change the culture you are faced with.
But good luck finding them.
-Rd
|
|
|
|
|
The instruction was very clear, exercise all aspects of the language features.
|
|
|
|
|
+3
Twas more like "as many features as you can muster"
...byte till it megahertz...
|
|
|
|
|
i didn't even know goto statement still exist...
dev
|
|
|
|
|
One of the worst programming practice i have ever seen was like this,
Dim Comma As String = ","
and then he used this variable whenever he wanted to used Comma in other strings.
Initially i wondered what this Comma means and then clicked go to definition and just horrified.
murder of programming......
|
|
|
|
|
if someone start to create a role play game like this:
int enemyHP = 10;
int playerStrength = 3;
_TakeDamage:
switch (playerStrength)
{
case 1:
if (enemyHP == 1)
{
goto _EnemyDeath;
}
else
{
enemyHP = enemyHP - 1;
}
case 2:
if (enemyHP == 2)
{
goto _EnemyDeath;
}
else
{
enemyHP = enemyHP - 2;
}
case 3:
if (enemyHP == 3)
{
goto _EnemyDeath;
}
else
{
enemyHP = enemyHP - 3;
}
case 4:
if (enemyHP == 4)
{
goto _EnemyDeath;
}
else
{
enemyHP = enemyHP - 4;
}
case 5:
if (enemyHP == 5)
{
goto _EnemyDeath;
}
else
{
enemyHP = enemyHP - 5;
}
}
_EnemyDeath:
Console.WriteLine("Enemy is death!");
Then there is no hope for the game... xD
This is really untopable!
|
|
|
|
|
In some old code, I discovered following gem:
do
{
try
{
BDTLine line = new BDTLine(File);
line.Read();
Lines.Add(line);
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine("Exception reading BDT file: "+ex.Message);
break;
}
} while(true);
The file seems to be read line by line, but actually line.Read() reads a number of bytes. Some when the end of the file is reached, and it reads the next 7 bytes, an exception is thrown which is caught in the block above, which then stops further reading of the file; the error message nicely fills the log file. Great idea!
|
|
|
|
|
Is this in Java?
The narrow specialist in the broad sense of the word is a complete idiot in the narrow sense of the word.
Advertise here – minimum three posts per day are guaranteed.
|
|
|
|
|
Nope, Java would have camelCase method names.
|
|
|
|
|
I'm not really a .NET programmer, so I might be missing something here. I would expect this to break out of the do-while loop after the exception has been logged. So, if it breaks out of the infinite loop after writing to the log, why would it fill the log file? And surely it will only write to the log file if Trace is enabled? So in a production environment I wouldn't expect it to write anything at all.
I'm not defending using infinite loops to process something that isn't endless like this, I think it's bad practice, but I don't understand why this would just keep writing error messages endlessly to the System Trace log, which is what the poster seems to suggest.
As I said, I'm not a C# programmer really, so maybe there's something going on here I'm not aware of.
|
|
|
|
|
you would be right if the while loop were inside the try block; as it is now, once something goes wrong the while loop keeps executing, causing ever more exceptions.
|
|
|
|
|
So, if this is C#, the break takes you where?
To find out, I tried this:
do
{
try
{
int a = 1;
int b = 0;
int c = a / b;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
break;
}
} while (true);
When the DivideByZeroException gets caught, it breaks out of the do-while loop, and does not keep showing the MessageBox over and over. Why is this different from the original example? I must be missing something obvious here.
|
|
|
|
|
You're right, the break prevents an eternal loop. Nevertheless the following is the normal way:
try
{
do
{
int a = 1;
int b = 0;
int c = a / b;
} while (true);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
as its structure better matches the intended operation, which is illustrated by the fact the break is not present anymore.
|
|
|
|
|
Either way, it's a pretty sucky way to do things. I'm guessing that this is forced on the programmer because the BDTLine class is badly designed so the only choice is to continue to read until it throws an exception.
|
|
|
|
|
But why us do with while(true) ?
|
|
|
|
|
I wouldn't. When I need forever, I use
for(;;) {...}
and in C I would even
#define forever for(;;)
and yes I know I could do that in other C-like languages too using the/a pre-processor.
|
|
|
|
|
Loop should exit on first exception if there is no try block. I agree with you in this case it wouldn't stop excuting as it has a catch block. But I wonder if it will ever throw end of file exception? as everytime a new Object is created against physical file that would start reading file from start so there would be no end of file ever. but it could throw infinite loop exception though?
Your thoughts?
R A M
|
|
|
|
|
You missed the break in the catch block. And so did I initially. It is ugly; if the goal is to leave the loop on exceptions, then the loop should sit inside the try block, not the other way around.
|
|
|
|
|
I understand.. but my point is will that read anything after first line as Object to read file is initiated EVERYTIME in loop
R A M
|
|
|
|
|
I can't tell from what is shown.
Is file a string, and BDTline opening said file?
or is file some kind of object (say a StreamReader), that has the file opened earlier on, and parses/returns a single line?
|
|
|
|
|
It breaks out of the loop with the first exception encountered, which is typically a System.IO.EndOfStreamException because the last line from which is read is always empty. And the normal way to leave that loop is exactly this exception. Every file read will cause three such lines in the log file (later on, the file is read another two times - it is certain that it has not changed between reads...). The next file causing another three lines in the log, and so on. When searching for the cause of a different error I was severely mislead by these messages.
|
|
|
|
|
This looks bad pratice to me, to break loop on exception, rather then actually detecting and comparing EOF character.
Ravi S
Coding is my birth-right and bugs are part of feature my code has!
_________________________________________
Me
Facebook
Twitter
|
|
|
|
|
Simply bad design and very poor naming conventions.
1) Call things what they are, nothing more, nothing less.
Class BDTLine should be BDTFile
line should be lines
.Read method should be .ReadLine (or should it be ReadBytes?)
Now when you look at the code you can see why it is loaded with problems.
2) BDTFile is an implementation nightmare for you or anyone else in the future.
2a) If the caller manages the loop, the class must expose a property to determine when to stop.
<br />
public bool EOF { <br />
get { return sr.Peek > -1; }
}<br />
<br />
_eof=((input=sr.ReadLine())==null)<br />
get { return _eof; }
2b) if the class manages the loop, either pass the lines reference or return the desired result from the Read method.
3) Finally there is no excuse for using do...while(true), period.
Dwayne J. Baldwin
|
|
|
|