|
Rhys Gravell wrote: Obviously the c# boolean type just isn't good enough in some places then
Correct, it's very limited. 
|
|
|
|
|
You lucky youngster! You cannot remeber the "Good" Old Days when Booleans had to be transformed to numbers. Well, "no" or "false" was generally 0, but "yes" or "true" had many definitions: 1, -1, 255 - these are just the most important ones I still remember.
And now imagine you have to write a new front end which communicates with a MUMPS server...
|
|
|
|
|
MUMPS server, now I feel a little ill
Rhys
"Technological progress is like an axe in the hands of a pathological criminal"
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe"
|
|
|
|
|
I am busy removing empty catch blocks from a project I have inherited (Yes, the same one as before, made by the same criminal. You can tell by those great 'Denglish' variable names). Now I have found a catch block that's not empty. Finally. And what is done to handle the error?
This:
try
{
MessageBox.Show(String.Format(tt.Readwert("t3"), Konstanten.Ftpprogdir), tt.Readwert("t2"),
MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
catch
{
MessageBox.Show("Programmverzeichnis fehlt", tt.Readwert("t2"),
MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
Edit: "Programmverzeichnis fehlt" means 'the program directory is missing'. How can that be when the program is obviously running when it hits those code lines? And how does he conclude that by having failed to open a MessageBox? This tt.Readwert-nonsense does not check any directories. It's just his own shot at localizing strings.
Edit^´2: And let's not forget that the error message in case of an exception will obviously not be localized
At least artificial intelligence already is superior to natural stupidity
modified 2-Jul-12 5:05am.
|
|
|
|
|
looks like some copy/paste error to me. Wouldn't surprise me if you do a quick search on "Programmverzeichnis fehlt", you will find that more often.
But yea, this looks like some bad error handling.
|
|
|
|
|
I think it actually makes sense (even if it is not the correct way to do it).
I bet that the programmer expected that something in the
Konstanten.Ftpprogdir property could throw an exception.
|
|
|
|
|
Hey, you can read his twisted mind! Would you please come over and help me with making sense of the rest of this mess?
You are right. He tries to tell us that the application directory is not there. The program runs on a mobile device and tries to get the latest version of itself when the device is docked. My friend here just could not figure out how a program that is currently running can update itself. Now, how can it possibly happen that the application directory is not there when the application itself is obviously running at that moment? He is trying to prevent an impossible error.
He is like the coyote when he builds another roadrunner trap. Everybody but him can see how it is going to end. And when it explodes in his face, he can't figure out why. Instead he simply wraps the problematic code in a 'try' and leaves the catch block empty. Nothing has happened, let's just go on with it. This time he at least tried to show some error message, but of course not without making a mess out of that simple task.
I have written it before: Tar him, feather him, throw him out of the guild and then chase him out of town.
At least artificial intelligence already is superior to natural stupidity
|
|
|
|
|
|
one of the many "DON'TS" in C++
i hope this tutorial is just a "do not"
|
|
|
|
|
I'm afraid not - it seems to be a genuine "tutorial" site...
Perhaps he is just doing job creation: "If I teach them to code like this, I can get the job of fixing it"?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Elephanting scary. Allocate a variable on the local stack frame, then return a pointer to it.
Definitely a make-work for somebody.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
I know what you mean. Way too easy to do by mistake, and a real PITA to find and fix in a big project. Definitely not something you should be teaching people to do.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
nevertheless the pointer is immediately dereferenced, so in this example it is perfectly OK 
|
|
|
|
|
Of course!
Don't you just love code that works more by luck than by judgement?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
A sudden sense of not being a hack has temporarily settled down over me.
|
|
|
|
|
You what!
Hmm, I spent many happy hours tracking down a strange bug in a database library I was using that was a subtle variant of this:
The library passed data objects by value, but treated them as passed by reference: this worked when compiled with Borland C++, because the optimiser effectively took away the creation of the temporary stack objects that are required by the spec and passed a reference. gcc did it properly though, and allocated the temporary objects and then threw them away - result, the system worked perfectly on Windows (compiled with Borland) and failed in mysterious ways on Linux.
To their credit, once I told the authors, they fixed it very quickly...
8)
Perhaps this chap used to work for them...
|
|
|
|
|
|
Why do you think it's a code horror? =P
Fratelli
|
|
|
|
|
Immediately after posting I realized where I was
|
|
|
|
|
This tutorial should be called: "How to get your first access violation runtime error in C++".
|
|
|
|
|
As you can see I went from a maximum of 68 LOC to the current size of 41 LOC. I didn’t manage to remove half of the code, but 40 % still isn’t bad for such a small amount of code. At least I don’t have to maintain those 27 removed lines anymore. At the same time the readability has improved a lot.
For completeness the final code:
using System;
using System.Collections.Generic;
namespace Gimp.AverageBlur
{
class AverageBlur : Plugin
{
static void Main(string[] args)
{
new AverageBlur(args);
}
AverageBlur(string[] args) : base(args, "AverageBlur")
{
}
override protected IEnumerable<Procedure> ListProcedures()
{
yield return new Procedure("plug_in_average_blur",
_("Average blur"),
_("Average blur"),
"Maurits Rijk",
"(C) Maurits Rijk",
"2006-2009",
_("Average"),
"RGB*, GRAY*")
{MenuPath = "<Image>/Filters/Blur"};
}
override protected void Render(Drawable drawable)
{
var iter = new RgnIterator(drawable, _("Average"));
var average = drawable.CreatePixel();
iter.IterateSrc(pixel => average.Add(pixel));
average /= iter.Count;
iter.IterateDest(() => average);
}
}
}
Please read My Last Article and suggest some better ideas.
---------Moving ahead with joy & struggle---------
--Amit
modified 1-Jul-12 20:14pm.
|
|
|
|
|
Just came across this SQL stored procedure (decluttered and anonymized):
CREATE PROCEDURE SomeProcedure
@switch AS int
AS
BEGIN
IF @switch = 1
BEGIN
END
ELSE
BEGIN
END
END
This pattern is repeated with many stored procedures. The variable "switch" was really called that and there were absolutely no comments of what that variable is supposed to toggle. At least the name hints that it toggles... surely I'd have been unable to figure that out from the IF statement. If this were a language with booleans, I'm certain they'd have named the variable "aBool".
|
|
|
|
|
Some people just should not be allowed near a computer.
public class SysAdmin : Employee
{
public override void DoWork(IWorkItem workItem)
{
if (workItem.User.Type == UserType.NoLearn){
throw new NoIWillNotFixYourComputerException(new Luser(workItem.User));
}else{
base.DoWork(workItem);
}
}
}
|
|
|
|
|
This is what I love about the system I work on.
Some values changed to protect the guilty
if( this.idtoservice != null )
{
sOwner = this.idtoservice.Common.Security.Owner;
}
else if( this.idtoservice != null )
{
sOwner = this.idtoservice.Common.Security.Owner;
}
else if( this.idtoservice != null )
{
sOwner = this.idtoservice.Common.Security.Owner;
}
- Arthur Souza
|
|
|
|
|
Was somebody being paid by the lines of code? Wow!
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|