Recent Articles

Sep 2004

It seems my app is running a little slow ...

by in Feature Articles on

Quite a few users were complaining about application performance so Keith investigated the problem. He came across this in a stored procedure that pointed him in the right direction  ...


The Best-est Version Control

by in Feature Articles on

I'm sure many of us have used SourcesSafe, the source control system that comes with our Microsoft development tools. Others have probably ventured into different systems like SourceGear and even the industrial strength AllFusion Harvest. And then there are those few, such as Bernhard Hofmann's colleague, who set everything else aside and invent their own method of version control:


$_PHP["logic"]

by in Feature Articles on

Don't get me wrong, I'm not saying that all logic contained within PHP pages is poor. Of course, any platform that blatantly mocks structured coding with “features“ like variable variables is prone to create a whole slew of programming travesties. But that isn't always the case. See, here's a perfect example of some production code that Paul discovered. This illogic could easily be coded on another platform ...


C++ does enough as it is

by in Feature Articles on

C/C++, although quite a powerful platform, doesn’t have much built-in functionality. Array bounds? Nope, it's not my job. Buffer overruns? Hey, I'm just writing what data you tell me to. Garbage collection? Seriously, do I look like your mother?

Still not content with this limited set of functionality, David Shay's colleague boycotted the String.compareTo() method and implemented his own. Of course, it doesn't actually work, but that's not the point ... C++ does enough as it is ... why should it have to compare strings to?


Perls of Clarity

by in Feature Articles on

I'm surprised that I haven't received more Perl or PHP submissions. I've used both languages a bit and it just seems with the implicit everything and variable variables (woo hoo, another self modifying work), we'd see a bit more of it. With that said, here goes the first (and only) Perl submission from Pope Foo Bar II, illustrating how fun it can be to avoid the built-in length function:

sub strlen ($)
#
# find length of a string.  split evaluated in a scalar context
# returns the number of substrings matched.  if the expr to split on is null,
# this should return the number of chars in the string.
#
# this function should really
# be put somewhere more centralized and just imported where needed.
{
  no warnings;   # ignore 'Use of implicit split to @_ is deprecated'
  my ($str) = @_;
  my $len = scalar(split //, $str);
  return $len;
}


A Wrapper Wrapper

by in Feature Articles on

Tell me that's not cool ... using the same word as a modifier to itself? It's almost as cool as today's code. Now, I did question this code, as it's a bit unreal even for our standards, but Chris assures me that someone actually did write it and submit it to be checked-in (and not as a joke).

 


JavaScript eval()

by in Feature Articles on

Here's yet another post that shows us that you don't need BASIC to be a bad coder. Some languages like Perl/PHP and JavasScript allow you to do some pretty, ummm, interesting things. Jared shares with us one of those features in JavasScript that lets you execute whatever code is stored in a string: 

 


C++++

by in Feature Articles on

David Shay sends in a rather innefficient way of summation in C++: to figure out how big 10 is, start from 1 and count to 10, each time u say a number, extend a finger. Count your fingers, and you should have ten!

Yes, this is C++. Sure, a VB “coder“ could do the same thing ... but I think this should get double WTF-points for not being in BASIC ...


To ISBN or not ISBN, that is the question

by in Feature Articles on

I'm trying, really I am. I don't want to have such a disproportionate amount of posts on VB/VBScript/ASP as opposed to the C#, Java, PHP, Perl, and all the others. But when folks like Ray S send in data validation functions from real, production systems like this, how can I resist?


Your $2000 Function

by in Feature Articles on

I've often wondered what kind of code you get when you pay a consultant $250 an hour. I figured it would be nothing short of awe-inspiring. And now that I've actually seen (thanks Will Nesbitt) code produced by a two-grand-a-day consultant from IBM, I can say that it is certainly is awe-inspiring ... just not in the way I had hoped.


IsDevelopmentMachine()

by in Feature Articles on

JeBe came across a rather innovative way of determining if the codebase is running in a development or production enviornment. The logic goes, if there are two IP addresses, and one of them is 127.0.0.1, then it must be a development machine. And how do you check what the IP addresses are? It's quite simple, actually ...


Proper Database Nondesign

by in Feature Articles on

I'll leave it to Kevin E. Ford to describe today's WTF:

So there I was (no sh!t) innocently evaluating an off-brand accounting package.  One of the things I wanted to look at was the table structure.  Right off the bat I noticed that there was no referential integrity constraints, strange but I can live with it. 


Well ... that's one way to Roundoff ...

by in Feature Articles on

When it comes to talking about Microsoft Access, it seems that two tiny versions of me *poof* into existence, each sitting on a shoulder. The guy on my right wears a suit and always reminds me how great of a tool Access is because it empowers small organizations to develop productivity and information systems. The other guy, sporting a “l337 h4x0r“ tee and cut-off jeans, screams in my ear that “Access is a complete abomination“ and that the tools to create applications should not be put in the hands of laymen.

For some odd reason, as I'm about to post this currency-rounding Access function (discovered by Jeff Smith), the business-savvy mini-me didn't even bother showing up ...


X-M-Hell

by in Feature Articles on

I'll bet I know what exactly what the author of this code (that Marvin Smit came across in a code review) was thinking. Here goes:

Jeeze, this XML stuff sucks. It's okay in concept, but there is simply no easy way to traverse XML, like as a directory path or something. There's not even a way to query documents without having to write your own parsing functions. And even if there was, I wouldn't even know where to begin looking for help. I wish some one would write a book on this crap. Oh well ...


... if, and that's a real big if, ...

by in Feature Articles on

I was really shooting for zero BASIC posts this week. I love the language, and it's sad how easy it is to do some pretty bizarre things. But, I just couldn't resist posting this code from Ben that just screams Simplify Me


Finally, we have the spec!

by in Feature Articles on

And how helpful and clear it is! For today's bonus post, Michael Pelletier sends in part of the spec he was given from a Business Analyst to develop the search function:

Performance Measurement Indicators
Indicator Response time
Measurement Search results are returned quickly


What does "begin transcation" do?

by in Feature Articles on

Ron Richardson stumbled across this code in a T-SQL stored procedure. Don't get me wrong, commenting your code is a great thing. However, I'm not exactly sure how much clarification the first comment provides ... 


Not quite getting that Object-polymorphism thing ...

by in Feature Articles on

Objects. Encapsulation of related fields and operations to make it easier to reuse and work with code. Easy enough!

Polymorphism. The ability to have objects behave in the same manner, through inheritance, interface, etc. Gotcha.


Converting Bytes to Kilobytes

by in Feature Articles on

Miles sends in a very interesting method of converting number of bytes to kilobytes:

numSize = len(fa.size) - 3
strSize = left(fa.size, numSize) & "K"


If only Java supported XML ...

by in Feature Articles on

... then Brade would never have come across this code written by an expensive Java consultant his company used.

public final class XmlGenerator {
  private static final char LEFT_BRACKET = "<";  
  private static final char RIGHT_BRACKET = ">";  
  private static final char Q_MARK = "?";  
  private static final char EQUAL = "=";  
  private static final char DOUBLE_QUOTE = "\"";  
  private static final char SLASH = "/";  
  private static final char SPACE = " ";  
  private static final char AMPERSAND = "&";  
  private static final char APOSTROPE = "'";  
  private static final String XML = "xml";  
  private static final String VERSION = "version";  
  private static final String VERSION_NO = "1.0";

  private static void appendXmlVersion(StringBuffer buffer) {
    buffer.append(LEFT_BRACKET);
    buffer.append(Q_MARK);
    buffer.append(XML);
    buffer.append(SPACE);
    buffer.append(VERSION);
    buffer.append(EQUAL);
    buffer.append(DOUBLE_QUOTE);
    buffer.append(VERSION_NO);
    buffer.append(DOUBLE_QUOTE);
    buffer.append(Q_MARK);
    buffer.append(RIGHT_BRACKET); 
}

Can you think of a worse solution than this?

by in Feature Articles on

Rajah Donalt sends in a stored procedure he came across in a production system. I'll bet you didn't know that this is the fastest way to select a row from a table from a primary key. At least, according to the author of the procedure.

CREATE PROCEDURE sp_get_order (
        @OrderID        int
) AS