|
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.
|
|
|
|
|
I'd say that was the definition of a 0 type of person 
|
|
|
|
|
is all I can say.
I think the coder forgot to call the TurnBrainOn() function before he started.
public class Coder: Employee{
public override bool Initialize(IInitializeContext init){
}
public string WriteCode(ICodeInfo info, ICodeContext ctxt){
}
}
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);
}
}
}
modified 26-Jun-12 16:16pm.
|
|
|
|
|
You need to also have the following after init.TurnBrainOn(this) :
if ( !CaffineLoaded() ) throw new NoCaffineException(this)
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
classic copy&paste thingy combined with "I'll express it later".
|
|
|
|
|
No no no! You do not understand that!
It is a very sophisticated, overly complicated multi-tasking application, with many threads running in parallel, and lots of things running in the cloud (and you never know what's happening there in the cloud).
So if this.idtoservice was still null at the first call, try it again, things might have changed meanwhile!
And do not try it more often than three times, three is the number...
|
|
|
|
|
Oops! It is complicated 
|
|
|
|
|
It's easier as do{ }while() loop.
|
|
|
|
|
|
Third time's the charm.
Three lefts make a right.
Three's company.
Threesomes.
The power of three (Charmed).
Three chances.
On the count of three.
One, two, three, go.
|
|
|
|
|
Some additional ones:
Three is a magic number. (Schoolhouse Rock)
What I tell you three times is true. (The Hunting of the Snark; Lewis Carroll)
|
|
|
|