Pages

Wednesday, July 26, 2006

Simplifying code

It has been a while since I have written a good simplify post. It has also been a while since I’ve posted several entries end to end
[java]
String fileName = file.getName();
if (fileName.endsWith(someValue)) {
return true;
} else {
return false;
}

[java]
String fileName = file.getName();
return fileName.endsWith(someValue));

Now I know it could be shortened to one line, but then things start looking a little long. If it was c# with properties, I might have gone with it.

-= Comments
1. Lucien | July 26th, 2006 at 11:07 am

The one liner for that isn’t so bad.

return file.getName().endsWith(value);

At least you didn’t start with:
[java]
String fileName = file.getName();
if (fileName.endsWith(someValue) == true) {
return true;
} else if (fileName.endsWith(someValue) == false) {
return false;
}



That’s the kind of newbie code I *love*

2. Mark | July 26th, 2006 at 12:24 pm
This one with css is a classic

border-top-color: #000000;
border-right-color: #000000;
border-bottom-color: #000000;
border-left-color: #000000;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;

The amount of times I see the above code is stunning..

border: 1px solid #000;

3. Matthew Delves | July 26th, 2006 at 12:27 pm
There is something always beautiful about simple code. It is easy to follow and as long as you know exactly what it does there can be less bugs.

4. Lucien | July 26th, 2006 at 12:43 pm
With the CSS example, I expect it’s auto generated by some tool (not the tool sitting in front of teh keyboard).

doesn’t make it any more acceptable. And since humans inevitably have to go in and tweak it when it’s not working, it just makes out job harder.

5. Clinton | July 26th, 2006 at 1:17 pm
I’ve seen a few tools "expand" css rules because they internally expand them to implement each feature (aka firefox+web developer -> css view etc).

A neat css tidy tool at http://csstidy.sourceforge.net/i but the informed human is still the elegant solution…

6. Lucien | July 26th, 2006 at 2:17 pm
What about an elegant human designing an informed solution?

7. Mark | July 27th, 2006 at 10:54 am
No, an informed designer building an elegant solution.

No comments:

Post a Comment