|
|
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)
|
|
|
|
|
Are you sure? Are you sure? Are you absolutely sure?
"Real men drive manual transmission" - Rajesh.
|
|
|
|
|
I suspect this was written by Walt.
|
|
|
|
|
This coder has been around a long time, you may remember the redundancy design, tell me 3 times, he has just incorporated it at a lower level!
BTW this could use a renaming for greater accuracy.
if( this.idiotservice != null )
{
sOwner = this.idiotservice .Common.Security.Owner;
}
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Of course it could be that Mycroft's renaming is extremely accurate and the disservice is changing some global variable such that it could return different values each time its called.
|
|
|
|
|
To be completely boring: looks like someone had a race condition. Although you still need to be insane to attempt threading without knowing anything about it.
He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chineese Proverb]
Jonathan C Dickinson (C# Software Engineer)
|
|
|
|
|
Well... if idiotservice were a getter that as part of its implementation attempts to connect to an external service, this could actually make a little bit of sense.
|
|
|
|