Feng Shui

It's sort of like a modern art sculpture carved out of dried cow manure. It looks kind of pretty there in the museum, but at the end of the day, it's really just a big pile of sh*t.

Bill's Kid2011-01-18 09:47

If I'm not mistaken, this is the "Statue" programming pattern often taught at Easter Island Institute of Technology.

baka08152011-01-18 09:49

Am I the only one seeing a beautiful lady leaning on a wall?

George2011-01-18 09:50

Under the spreading B11CFee,
I soldU and you soldB.
There we lie and there EscB,
under the spreading R5Fee.

Gary2011-01-18 09:51

It was an entry in the Obfuscated VBA contest. Which is why it is a slumping, flaccid mess.

pinkduck2011-01-18 09:54

I like how only the last variable on each line is given an actual type, the rest just empty/uninitialised variants.

szeryf2011-01-18 09:57

...and the algorithm for arranging the variable declarations in this way is NP-complete, mind you.

Jason2011-01-18 10:01

Isn't it supposed to be a vase?

shotcircut2011-01-18 10:03

Isn't all VBA?

Another Anonymous2011-01-18 10:04

So this is what they mean when they say programming is an art?

(Also, this guy was obviously not paid per line.)

frits2011-01-18 10:08

Poor Trent, may he rest in peace...

Migala2011-01-18 10:08

ProsDirty1 StripTot
FER FedFee
EnID soldU StringID
GRat1

Drum D.2011-01-18 10:09

Against the long spreading rumour that the universe is constantly expanding I have to tell you it is not.

What we see here - wonderfully carved in VBA - is the plotted extension data starting from the Big Bang up until the present day.

Time increasing top to bottom, size increasing left to right.

trwtf2011-01-18 10:09

Isn't it supposed to be a vase?

shotcircut:

Isn't all VBA?

No, some VBA is supposed to be two faces. And some is supposed to be a duck, and some is supposed to be a rabbit.

Steve The Cynic2011-01-18 10:16

trwtf:

Isn't it supposed to be a vase?

shotcircut:

Isn't all VBA?

No, some VBA is supposed to be two faces. And some is supposed to be a duck, and some is supposed to be a rabbit.

No quack.

Iron fisted bit flipper2011-01-18 10:16

This technique takes software craftsmanship to a whole new level.

Doozerboy2011-01-18 10:17

My first programming gig was much the same.

All the code in one module, took 15 minutes to open, all controls on the forms called checkbox12, checkbox15 etc etc. The front end alone was a mammoth 1/2 GB as the developer hadn't bothered to split his UI from his data.

Fortunately i had a sympathetic boss who let me bin it and start again from scratch.

Doozerboy2011-01-18 10:19

baka0815:

Am I the only one seeing a beautiful lady leaning on a wall?

If it is, she's only thinking about the money.

Trent2011-01-18 10:19

God dang it...you are displaying my art sideways again!

Cad Delworth2011-01-18 10:19

It sort of resembles a 90-degree rotated graph of something. Perhaps of the developer's likelihood of leaving that company to work elsewhere?

Also, good point Feng made about no Type on most variables! Obviously I've been writing far too much Delphi/Javascript lately! Maybe the guy only wrote Windows Script rather than VBA, and assumed 'they'll be the same...'?

Bobbo2011-01-18 10:20

Steve The Cynic:

No quack.

I think somebody has already had plenty of quack.

da Doctah2011-01-18 10:22

The variables were often given incoherent and inconsistent names, and in many cases, vowels were dropped from names where they should have belonged. Maybe he felt that by not using vowels it would be a cost savings for the company Mike chuckled to himself

Public AT1 As Long
Public GetB As Long
Public PradPs As Long
Public Geta1ID As Long
Public StringID As Long
Public ProformID As Long
Public CreatedID1 As Long
Public TickerTal1s As Long
Public InvalidCount As Long
Public PrmID, ImptID As Long
Public EnID, InvaldID As Long
Public RdID, RefundedID As Long
Public OffWeightedSum As Currency
Public B11CFee, PortFee As Currency
Public RSDPctAr, FoldPct As Currency
Public DS1, DS2, DS3, AS4 As Currency
Public InvldMet, FER, AS1 As Currency
Public RevUpPct, RvUpPost As Currency
Public RV1, RV2, RV3, BSS4 As Currency
Public FFF, NCF1, BB1, B1A As Currency
Public EscA, EscB, InvaldT As Currency
Public RSDFee, FedFee, R5Fee As Currency
Public StripTot, StripTotalPct As Currency
Public ValPrt, PretextVar, G1, R1 As Currency
Public PartAff12, affixedMost, GRat1 As Currency
Public ProsDirty1, ProcSpl, CartSplit1 As Currency
Public PC5A, PC3A, PC4A, P3B1, PCU, PCR As Currency
Public DC5, DC3, DgCA, DcM, DCB, DCU, DCR As Currency
Public RftUpPct1, RftUpPosted1, RftUpPat2 As Currency
Public rptAffordeD, raptCapped, rptPostand As Currency
Public B5DP, B3DP, BMAP, BARP, BUPP, BREP1 As Currency
Public GtQ5, GtQ3, GTQA, GTQM1, GTQB1, GQU As Currency
Public Var1, Var2, Var3A, VarM1, VarU4, VAR As Currency
Public Save2S, Save3A, Save4A, Save5A, Save12 As Currency
Public Gubr2, GUBR1, GubrA, GubrB, GubrC, GubrU As Currency
Public PercentB, Percent35U, PercentU, PercentR As Currency
Public PercentF, PercentD, PercentRSD, PcentD1H As Currency
Public Prod7Sum, ProdBBSum, ProdAM1Sum, ProdBSum As Currency
Public PercentJS, PercentJ7, PercentJ5, PercentJ1 As Currency
Public Disr1A, DISR3A, Disr5, DisrB, DiscrA, Disr6 As Currency
Public ProdRLSum, ProdRSum, ProdRSDSum, ProdR06Sum As Currency
Public ProdR, ProdM, ProdN, ProdFD, ProdRSD, ProdD1H As Currency
Public ProdP, ProdPSum, ProdRSum, ProdTSum, ProdFSum As Currency
Public Port1, Port3, PostA, PostB, Post2, Post3, PostD As Currency
Public Prod2, Prod1, Prod3, ProdH, ProdE, ProdB, ProdQ As Currency
Public PosandAllowd, PosandStopd, PortandDue, Serv1scart As Currency
Public Port6Sum, Port9Sum, PortB4Sum, PortHSum, PortHSum As Currency
Public soldG, Sold12, soldB, SoldX, SoldY, soldZ, sold44 As Currency
Public Disc7Sum, Disc8Sum, DiscB4Sum, DiscUJSum, SaveWSum As Currency
Public rptPrt4, rptPrt6, rptPrtJ1, rptPrtI, rptPortB, rptP As Currency
Public soldU, soldPU, SoldH, SoldI, SoldJ, SoldN, SoldF, soldUP As Currency
Public SoldRAS, SoldR11, SoldR12, SoldR13, SoldD1, SoldD2, SoldSP, SoldPC As Currency

Iie2011-01-18 10:25

Bill's Kid:

If I'm not mistaken, this is the "Statue" programming pattern often taught at Easter Island Institute of Technology.

Hit CTRL+A and it will shoot lasers out its eyes.

TheSHEEEP2011-01-18 10:26

"Gubr2, GUBR1, GubrA, GubrB, GubrC, GubrU"

Hey, that's Obelix!
Gubr Gubr Gubr Gubr!

boog2011-01-18 10:27

Actually, this is beautiful from a maintenance perspective. Now Mike has a list of all of the global variables to use in his find-and-replace.

TheSHEEEP2011-01-18 10:29

"Gubr2, GUBR1, GubrA, GubrB, GubrC, GubrU"

Hey, that's Obelix!

Vilx-2011-01-18 10:32

It's like a christmas tree!

blah2011-01-18 10:32

pinkduck:

I like how only the last variable on each line is given an actual type, the rest just empty/uninitialised variants.

Really? Yuck. So glad I've had so little exposure to VB/VBA.

TheCPUWizard2011-01-18 10:35

Does anyone remember a poster from a computer software company in the mid-1980's where the backdrop looked like a "misty mountain range", but upon closer examination was a reclining naked woman????

If anyone knows of a reproduction (or even better has an original!!!) please contact me directly.

boog2011-01-18 10:43

Cad Delworth:

It sort of resembles a 90-degree rotated graph of something. Perhaps of the developer's likelihood of leaving that company to work elsewhere?

I was going to suggest the same thing; it's the developer's intent to resign as a function of time. That makes me wonder what the valleys (around InvldMet, RftUpPct1, and PercentB) must mean. Maybe they represent weekends?

SCSimmons2011-01-18 10:54

blah:

pinkduck:

I like how only the last variable on each line is given an actual type, the rest just empty/uninitialised variants.

Really? Yuck. So glad I've had so little exposure to VB/VBA.

Wow. I've had way too much exposure to VBA, and I was not aware of that. (Although I'm pretty sure that I've always declared one variable per line, so it wouldn't have come up in my code.) But I checked the documentation, and blah is absolutely right--the VBA compiler really does interpret those declarations that way. You need to put an 'As Long' or whatever after each variable name--as this code is written, most of the variables are untyped variants.

But I suppose explicitly writing all of the declarations would have interrupted the aesthetic flow of the code.

dpm2011-01-18 11:00

Someone help me out here, I can't find Waldo.

Grumpy2011-01-18 11:01

baka0815:

Am I the only one seeing a beautiful lady leaning on a wall?

Yes. Yes, you are. Please get adult supervision.

frits2011-01-18 11:01

baka0815:

Am I the only one seeing a beautiful lady leaning on a wall?

All I see is a haggard old lady.

trwtf2011-01-18 11:10

frits:

baka0815:

Am I the only one seeing a beautiful lady leaning on a wall?

All I see is a haggard old lady.

I don't see what Merle Haggard's old lady has to do with any of this.

Lewis2011-01-18 11:12

Twas brillig, and the soldZ TickerTal1s,
Did Geta1ID and GubrU in the wabe:
All Post3 were the PosandAllowd,
And the RftUpPat2 GubrA

Anonymous2011-01-18 11:15

*now reformatting my current project source code*

Anonymous2011-01-18 11:24

I always try to arrange variable declarations by line length. We're talking about a handful of function-level declarations rather than a stinking mess of globals, but I always find myself putting them into some kind of natural order and it's normally by length (sometimes alphabetical if that looks more asthetically pleasing). It's not a code thing since every book I own is arranged in height order as well. If I washed a bit more often I would highly suspect OCD but as it stands I'm probably just time-wasting.

Mike2011-01-18 11:33

It's all about using the right tool for the job. In this case, they used a lathe.

Patrick2011-01-18 11:38

It looks like Rageface side-on

The Configurator2011-01-18 11:53

More like a fright calculator...

Jaime2011-01-18 12:01

SCSimmons:

blah:

pinkduck:

I like how only the last variable on each line is given an actual type, the rest just empty/uninitialised variants.

Really? Yuck. So glad I've had so little exposure to VB/VBA.

Wow. I've had way too much exposure to VBA, and I was not aware of that. (Although I'm pretty sure that I've always declared one variable per line, so it wouldn't have come up in my code.) But I checked the documentation, and blah is absolutely right--the VBA compiler really does interpret those declarations that way. You need to put an 'As Long' or whatever after each variable name--as this code is written, most of the variables are untyped variants.

But I suppose explicitly writing all of the declarations would have interrupted the aesthetic flow of the code.

Interestingly, the declarations would work properly in VB.Net. Usually people who make these atrocoties are way behind in technology, but this guy seems to be ahead of himself.

Jay2011-01-18 12:19

Anonymous:

I always try to arrange variable declarations by line length. ... I would highly suspect OCD but as it stands I'm probably just time-wasting.

You mean CDO. You should put the letters in alphabetical order like they belong.

NutDriverLefty2011-01-18 12:21

boog:

Now Mike has a list of all of the global variables to use in his find-and-replace.

I bet he doesn't!

Jay2011-01-18 12:21

I can see how this program would be difficult to maintain. Every time you create a new variable, not only do you have to come up with a name that concisely expresses the semantic purpose of the variable within the program, but you also have to make sure that the length of the name will fit properly with the aesthetic layout of the declaration list.

Dr.Evil2011-01-18 12:47

I see it, it's a sailboat!

bikeoid2011-01-18 12:59

Now we know how the Easter Island statues came to be...an ancient alien civilization programming in VB noticed this beautiful pattern in their global variables and decided to memorialize them in stone.

sprezzatura2011-01-18 13:07

Actually, this could be a fun project, especially if it looks like you will be stuck with maintaining the Freight Calculator for the rest of your time at this company.

The goal would be to gradually eliminate as many global variables as possible, by replacing them with parameters that are passed from one function to the next (assuming this system has more than one function).

Start by picking a variable, seeing where it is used, then declare it as a local at the highest level of the stack, and change the function call(s) to pass it as an argument to the functions.

Little by little, you will transform the globals into locals, creating order and beauty in this labyrinth. Imagine the satisfaction and sense of accomplishment. In the process you will develop an understanding of the app, and add documentation throughout the code. Discover the beauty in the humblest of things.

The Bytemaster2011-01-18 13:07

pinkduck:

I like how only the last variable on each line is given an actual type, the rest just empty/uninitialised variants.

I did not realize that about VBA. VB6 and later would initialize to the correct type for a statement formatted like that.

frits2011-01-18 13:20

sprezzatura:

Actually, this could be a fun project, especially if it looks like you will be stuck with maintaining the Freight Calculator for the rest of your time at this company.

The goal would be to gradually eliminate as many global variables as possible, by replacing them with parameters that are passed from one function to the next (assuming this system has more than one function).

Start by picking a variable, seeing where it is used, then declare it as a local at the highest level of the stack, and change the function call(s) to pass it as an argument to the functions.

Little by little, you will transform the globals into locals, creating order and beauty in this labyrinth. Imagine the satisfaction and sense of accomplishment. In the process you will develop an understanding of the app, and add documentation throughout the code. Discover the beauty in the humblest of things.

You're kidding, right?

boog2011-01-18 13:21

NutDriverLefty:

boog:

Now Mike has a list of all of the global variables to use in his find-and-replace.

I bet he doesn't!

Are you suggesting that developers that are obsessive enough to sculpt visual patterns in code (even obfuscating variable names to fit the visual pattern) might not be obsessive enough to follow an organizational pattern between files (such as storing all variables in a single file)?

The funny thing is that you're probably right. My theory is that developers who obsess over the visual appearance of their code usually do so because the code is lousy. Without any way to sanely organize existing spaghetti code, the only option they know of is to make it look pretty.

That might be what happened with Trent.

Englebart2011-01-18 13:22

I thought that Easter Island was proven to be the first binary computer.

Each statue represented a one bit. A blank in the formation was a 0 bit.

The entire island died of starvation while the head programmer was trying to debug his first program.

Interestingly enough, the program was finally rewritten by some guy named Conway who called it Life.

P.S. The Easter island bug was in the sparse array logic.

boog2011-01-18 13:28

frits:

sprezzatura:

Actually, this could be a fun project, especially if it looks like you will be stuck with maintaining the Freight Calculator for the rest of your time at this company.

The goal would be to gradually eliminate as many global variables as possible, by replacing them with parameters that are passed from one function to the next (assuming this system has more than one function).

Start by picking a variable, seeing where it is used, then declare it as a local at the highest level of the stack, and change the function call(s) to pass it as an argument to the functions.

Little by little, you will transform the globals into locals, creating order and beauty in this labyrinth. Imagine the satisfaction and sense of accomplishment. In the process you will develop an understanding of the app, and add documentation throughout the code. Discover the beauty in the humblest of things.

You're kidding, right?

Surely you're not suggesting that there might be something wrong with repeatedly making structural changes to working code without any functional benefit whatsoever?

trwtf2011-01-18 13:28

Englebart:

P.S. The Easter island bug was in the sparse island vegetation.

ftfy

benmurphyx2011-01-18 13:32

You get Variants in VB6 for all but the last variable in this case as well. The "auto-resolution" of type (whatever you want to call it) didn't start until .net.

trwtf2011-01-18 13:39

boog:

frits:

sprezzatura:

Actually, this could be a fun project, especially if it looks like you will be stuck with maintaining the Freight Calculator for the rest of your time at this company.

The goal would be to gradually eliminate as many global variables as possible, by replacing them with parameters that are passed from one function to the next (assuming this system has more than one function).

Start by picking a variable, seeing where it is used, then declare it as a local at the highest level of the stack, and change the function call(s) to pass it as an argument to the functions.

Little by little, you will transform the globals into locals, creating order and beauty in this labyrinth. Imagine the satisfaction and sense of accomplishment. In the process you will develop an understanding of the app, and add documentation throughout the code. Discover the beauty in the humblest of things.

You're kidding, right?

Surely you're not suggesting that there might be something wrong with repeatedly making structural changes to working code without any functional benefit whatsoever?

He is suggesting that refactoring is a good idea. And don't call him shirley.

VB6slave2011-01-18 13:51

The Bytemaster:

pinkduck:

I like how only the last variable on each line is given an actual type, the rest just empty/uninitialised variants.

I did not realize that about VBA. VB6 and later would initialize to the correct type for a statement formatted like that.

That's a big negative on the VB6 interpreting those declarations like C.

Dim i, j As Long
Debug.Print VarType(i), VarType(j)

Output:
0 3

0 = Empty (null), something a Long in VB6 cannot be
3 = Long Integer

boog2011-01-18 13:52

trwtf:

boog:

frits:

You're kidding, right?

Surely you're not suggesting that there might be something wrong with repeatedly making structural changes to working code without any functional benefit whatsoever?

He is suggesting that refactoring is a good idea. And don't call him shirley.

sprezzatura suggested that refactoring is a good idea. If I'm not mistaken, shirl..uh..frits was questioning that suggestion. As was I (but indirectly through sarcasm).

Peter2011-01-18 14:18

sprezzatura:

The goal would be to gradually eliminate as many global variables as possible, by replacing them with parameters that are passed from one function to the next (assuming this system has more than one function).

I suspect that you may be making an overly optimistic assumption.

Alfred2011-01-18 14:23

I like to do this with my makefiles. It makes waiting for the code to compile on a larger project much more bearable.

Gunslinger2011-01-18 14:48

boog:

The funny thing is that you're probably right. My theory is that developers who obsess over the visual appearance of their code usually do so because the code is lousy. Without any way to sanely organize existing spaghetti code, the only option they know of is to make it look pretty.

I disagree. Well-written code is visually pretty and badly written code is very difficult to make it look pretty.

boog2011-01-18 15:13

Gunslinger:

boog:

The funny thing is that you're probably right. My theory is that developers who obsess over the visual appearance of their code usually do so because the code is lousy. Without any way to sanely organize existing spaghetti code, the only option they know of is to make it look pretty.

I disagree. Well-written code is visually pretty and badly written code is very difficult to make it look pretty.

Please read more carefully. I did not imply that well-written code is not visually pretty.

What I did suggest, however, is that an obsessive programmer working on badly written code will try to make it visually prettier as a futile attempt to "improve" the code.

But it seems you weren't disagreeing with the overall theory, rather the assumption that poorly-written code can "look pretty". If you still disagree with that, then I submit today's article as evidence.

North Bus2011-01-18 15:16

Lewis:

Twas brillig, and the soldZ TickerTal1s,
Did Geta1ID and GubrU in the wabe:
All Post3 were the PosandAllowd,
And the RftUpPat2 GubrA

Under the spreading B11CFee,
I soldU and you soldB.
There we lie and there EscB,
under the spreading R5Fee.

Nice poem, comrade.

Coyne2011-01-18 18:07

Might be beautiful, but maintainability: VOID

Enlightened One2011-01-18 18:26

OK i get it, the more global variable you have, the prettier the code gets !

What an incredible breakthrough in software design !

chrismcb2011-01-18 18:34

Gunslinger:

boog:

The funny thing is that you're probably right. My theory is that developers who obsess over the visual appearance of their code usually do so because the code is lousy. Without any way to sanely organize existing spaghetti code, the only option they know of is to make it look pretty.

I disagree. Well-written code is visually pretty and badly written code is very difficult to make it look pretty.

Well written code is no more visaully pretty than a Pollack is.

Sutherlands2011-01-18 19:08

Dr.Evil:

I see it, it's a sailboat!

No, it's a schooner you idiot.

junior2011-01-18 19:41

Jaime:

Interestingly, the declarations would work properly in VB.Net.

That's because 'VB.Net' is NOT VB. It's a damaged C# kludge.

In BASIC, all the declarations are self contained, not line delimited.

DIM a_string$, a_float!, a_double#, a_long&

Cheong2011-01-18 21:15

I'd recommand download and using Access 2003 developer extension if his company has access to MSDN subscription.

It was helpful when I was handling an Access 2000 project years ago...

Steve2011-01-18 21:32

It's a longneck beer bottle.

Steve2011-01-18 21:33

My name:

Sort the lines by length, damnit!

Public AT1 As Long
Public GetB As Long
Public PradPs As Long
Public Geta1ID As Long
Public StringID As Long
Public ProformID As Long
Public CreatedID1 As Long
Public TickerTal1s As Long
Public InvalidCount As Long
Public PrmID, ImptID As Long
Public EnID, InvaldID As Long
Public RdID, RefundedID As Long
Public OffWeightedSum As Currency
Public B11CFee, PortFee As Currency
Public RSDPctAr, FoldPct As Currency
Public DS1, DS2, DS3, AS4 As Currency
Public InvldMet, FER, AS1 As Currency
Public RevUpPct, RvUpPost As Currency
Public RV1, RV2, RV3, BSS4 As Currency
Public FFF, NCF1, BB1, B1A As Currency
Public EscA, EscB, InvaldT As Currency
Public RSDFee, FedFee, R5Fee As Currency
Public StripTot, StripTotalPct As Currency
Public ValPrt, PretextVar, G1, R1 As Currency
Public PartAff12, affixedMost, GRat1 As Currency
Public ProsDirty1, ProcSpl, CartSplit1 As Currency
Public PC5A, PC3A, PC4A, P3B1, PCU, PCR As Currency
Public DC5, DC3, DgCA, DcM, DCB, DCU, DCR As Currency
Public RftUpPct1, RftUpPosted1, RftUpPat2 As Currency
Public rptAffordeD, raptCapped, rptPostand As Currency
Public B5DP, B3DP, BMAP, BARP, BUPP, BREP1 As Currency
Public GtQ5, GtQ3, GTQA, GTQM1, GTQB1, GQU As Currency
Public Var1, Var2, Var3A, VarM1, VarU4, VAR As Currency
Public Save2S, Save3A, Save4A, Save5A, Save12 As Currency
Public Gubr2, GUBR1, GubrA, GubrB, GubrC, GubrU As Currency
Public PercentB, Percent35U, PercentU, PercentR As Currency
Public PercentF, PercentD, PercentRSD, PcentD1H As Currency
Public Prod7Sum, ProdBBSum, ProdAM1Sum, ProdBSum As Currency
Public PercentJS, PercentJ7, PercentJ5, PercentJ1 As Currency
Public Disr1A, DISR3A, Disr5, DisrB, DiscrA, Disr6 As Currency
Public ProdRLSum, ProdRSum, ProdRSDSum, ProdR06Sum As Currency
Public ProdR, ProdM, ProdN, ProdFD, ProdRSD, ProdD1H As Currency
Public ProdP, ProdPSum, ProdRSum, ProdTSum, ProdFSum As Currency
Public Port1, Port3, PostA, PostB, Post2, Post3, PostD As Currency
Public Prod2, Prod1, Prod3, ProdH, ProdE, ProdB, ProdQ As Currency
Public PosandAllowd, PosandStopd, PortandDue, Serv1scart As Currency
Public Port6Sum, Port9Sum, PortB4Sum, PortHSum, PortHSum As Currency
Public soldG, Sold12, soldB, SoldX, SoldY, soldZ, sold44 As Currency
Public Disc7Sum, Disc8Sum, DiscB4Sum, DiscUJSum, SaveWSum As Currency
Public rptPrt4, rptPrt6, rptPrtJ1, rptPrtI, rptPortB, rptP As Currency
Public soldU, soldPU, SoldH, SoldI, SoldJ, SoldN, SoldF, soldUP As Currency
Public SoldRAS, SoldR11, SoldR12, SoldR13, SoldD1, SoldD2, SoldSP, SoldPC As Currency

It's a long neck beer bottle.

ABT2011-01-18 22:13

the real WTF is that in VBA (unlike VB proper), the last variable is the only one that gets assigned the variable type passed. For instance, in this line:
Public PrmID, ImptID As Long

only ImptID is cast as a Long. PrmID is cast as the default -- a memory clogging 'Object' type.

- ABT

Phlip2011-01-19 00:29

To confirm what others are saying... in the BASIC variants I've used extensively (QBasic, VB3, VB6... luckily I managed to drop the whole thing before .net), the line

Dim Foo, Bar as Type

is the same as

Dim Bar as Type, Foo

and ends up like:

Dim Foo as Variant, Bar as Type

But really, I'm tempted to become a VB consultant so I can scatter random people's code with

Dim I%, Msg$, Money@

and see how many people can figure it out... Did you know that, according to the VB.net docs, that syntax isn't even deprecated? Neither is On Error Resume Next... they just "recommend" doing something sane with Try/Catch.

Scythe2011-01-19 02:31

If you look at these lines from a larger distance you can almost see a christmas tree!

Sudo2011-01-19 02:35

Some people should count their blessings... I had to sort out an Access/VBA "app" once that was "written" by a lady who apparently didn't know about variables. Everything was done with big, nasty one-liners, or queries.
I wish when I quit that job I didn't ceremonially trash every trace of it from my home system - at the time I didn't know about TDWTF - it would've surely got featured.

m2011-01-19 03:13

In fact it's a Rorschachtest for code monkeys.

Shooey2011-01-19 05:12

Ah, the flow of a software project.

Shooey2011-01-19 05:14

a module named simply "Variables"

I wonder what the other modules were called.
"Functions" and "Macros"?

Anonymous2011-01-19 05:40

This wasn't written by a programmer. It was a manager in disguise:

As a manager, you'll interrupt at random, read the first and last page, and then you know what to do. In here: The first character and the last word of line 18-25

Public FFF, NCF1, BB1, B1A As Currency
Public InvldMet, FER, AS1 As Currency
Public RevUpPct, RvUpPost As Currency
Public EscA, EscB, InvaldT As Currency
Public RSDFee, FedFee, R5Fee As Currency
Public StripTot, StripTotalPct As Currency
Public ValPrt, PretextVar, G1, R1 As Currency
Public PartAff12, affixedMost, GRat1 As Currency

Translated: Fire her please, and you'll get a lot of money

anon2011-01-19 05:56

Phlip:

To confirm what others are saying...

This should have been the point that you realised your comment had nothing useful to add to the discussion and was merely an unnecessary reinforcement of a dozen other comments. Yet you felt the need to finish it anyway, very strange.

Brendan2011-01-19 06:12

Anonymous:

I always try to arrange variable declarations by line length. We're talking about a handful of function-level declarations rather than a stinking mess of globals, but I always find myself putting them into some kind of natural order and it's normally by length (sometimes alphabetical if that looks more asthetically pleasing). It's not a code thing since every book I own is arranged in height order as well. If I washed a bit more often I would highly suspect OCD but as it stands I'm probably just time-wasting.

Please do everyone else a favour and start arranging variables alphabetically. It's the one true way.

Larry David Jr2011-01-19 06:24

Iron fisted bit flipper:

This technique takes software crapmanship to a whole new level.

FTFY

Larry David Jr2011-01-19 06:45

Brendan:

Anonymous:

I always try to arrange variable declarations by line length. We're talking about a handful of function-level declarations rather than a stinking mess of globals, but I always find myself putting them into some kind of natural order and it's normally by length (sometimes alphabetical if that looks more asthetically pleasing). It's not a code thing since every book I own is arranged in height order as well. If I washed a bit more often I would highly suspect OCD but as it stands I'm probably just time-wasting.

Please do everyone else a favour and start arranging variables alphabetically. It's the one true way.

I arrange mine in the order of how much I like them. If one of them pisses me off, it gets put to the bottom.

rd2011-01-19 07:25

Please! Seek psychiatric help NOW!

frits2011-01-19 08:54

rd:

frits:

baka0815:

Am I the only one seeing a beautiful lady leaning on a wall?

All I see is a haggard old lady.

Please! Seek psychiatric help NOW!

Obviously you're not a married man, or you'd be able to sympathize.

sprezzatura2011-01-19 12:05

boog:

frits:

sprezzatura:

Actually, this could be a fun project, especially if it looks like you will be stuck with maintaining the Freight Calculator for the rest of your time at this company.

(...)

You're kidding, right?

Surely you're not suggesting that there might be something wrong with repeatedly making structural changes to working code without any functional benefit whatsoever?

No, I'm serious. There is a benefit: increased comprehension and maintainability. The restructuring is a precursor to overhauling the code. Once you have made the code more understandable, then you can start improving it.

I'm a business owner as well as a programmer. You don't just throw code away because your predecessor didn't do things your way. In the real World, you can't always afford to start from scratch.

Since I started writing code in 1965, it seems to have worked out OK so far. (No, I don't do COBOL and FORTRAN anymore, just C++, C#, PHP).

Don't tell me you are not sorting your variable declarations alphabetically and by length.

boog2011-01-19 14:02

sprezzatura:

No, I'm serious. There is a benefit: increased comprehension and maintainability.

I said functional benefit. There is no functional benefit, because the goal is to have code that functions the exact same way. So if the code works, refactoring is just trying to fix something that isn't broken. And if you lack a decent test environment, you risk breaking code that already works.

That isn't to say that cleaning code up is never necessary; I just think it should be on an as-needed basis. If you're faced with fixing a bug or adding a feature, refactoring (or just rewriting) the relevant portion of code as needed can be helpful to fix/add the bug/feature. But a project with the sole purpose of restructuring code to do what it already does seems like madness to me.

sprezzatura:

You don't just throw code away because your predecessor didn't do things your way. In the real World, you can't always afford to start from scratch.

True, you don't just throw it away; you archive it. And if you already have working code with a working design, even if it is poorly-written, you're not technically starting from scratch.

I understand your point; it's not always an affordable solution. I would suggest though that spending your time on a "fun project" like refactoring could be just as expensive. How would you know beforehand which might be more costly?

sprezzatura:

Since I started writing code in 1965, it seems to have worked out OK so far.

True, YMMV. I can really only comment based on the experiences/observations of myself and others with whom I've discussed refactoring.

Pyrexkidd2011-01-19 18:34

sprezzatura:

Actually, this could be a fun project, especially if it looks like you will be stuck with maintaining the Freight Calculator for the rest of your time at this company.

The goal would be to gradually eliminate as many global variables as possible, by replacing them with parameters that are passed from one function to the next (assuming this system has more than one function).

Start by picking a variable, seeing where it is used, then declare it as a local at the highest level of the stack, and change the function call(s) to pass it as an argument to the functions.

Little by little, you will transform the globals into locals, creating order and beauty in this labyrinth. Imagine the satisfaction and sense of accomplishment. In the process you will develop an understanding of the app, and add documentation throughout the code. Discover the beauty in the humblest of things.

Uhhh... Why not just scrap it and write it better. Like in another language?

MarkJ2011-01-19 19:03

SCSimmons:

blah:

pinkduck:

I like how only the last variable on each line is given an actual type, the rest just empty/uninitialised variants.

Really? Yuck. So glad I've had so little exposure to VB/VBA.

Wow. I've had way too much exposure to VBA, and I was not aware of that. (Although I'm pretty sure that I've always declared one variable per line, so it wouldn't have come up in my code.) But I checked the documentation, and blah is absolutely right--the VBA compiler really does interpret those declarations that way. You need to put an 'As Long' or whatever after each variable name--as this code is written, most of the variables are untyped variants.

But I suppose explicitly writing all of the declarations would have interrupted the aesthetic flow of the code.

If you've had that much exposure to VBA, perhaps you should see your personal physician...or perhaps an oncologist.

YousaidtomeBear2011-01-20 04:56

... but what does it mean...?!

Whhooooooo!

Oh my goood. All the way across the code. *sob* *tubular bells in the background*

Ahhhh! Aooh!

Anonymous2011-01-20 12:03

sprezzatura:

boog:

frits:

sprezzatura:

Actually, this could be a fun project, especially if it looks like you will be stuck with maintaining the Freight Calculator for the rest of your time at this company.

(...)

You're kidding, right?

Surely you're not suggesting that there might be something wrong with repeatedly making structural changes to working code without any functional benefit whatsoever?

I'm a business owner as well as a programmer.

And the mystery is solved. We've all worked with a "business owner as well as a programmer". They're responsible for a large proportion of the articles on this site.

hoodaticus2011-01-20 12:18

sprezzatura:

Actually, this could be a fun project, especially if it looks like you will be stuck with maintaining the Freight Calculator for the rest of your time at this company.

The goal would be to gradually eliminate as many global variables as possible, by replacing them with parameters that are passed from one function to the next (assuming this system has more than one function).

Start by picking a variable, seeing where it is used, then declare it as a local at the highest level of the stack, and change the function call(s) to pass it as an argument to the functions.

Little by little, you will transform the globals into locals, creating order and beauty in this labyrinth. Imagine the satisfaction and sense of accomplishment. In the process you will develop an understanding of the app, and add documentation throughout the code. Discover the beauty in the humblest of things.

I really hope you're kidding. This is not a target for refactoring. This is a target for re-write. In a real language like C#.

hoodaticus2011-01-20 12:19

Anonymous:

And the mystery is solved. We've all worked with a "business owner as well as a programmer". They're responsible for a large proportion of the articles on this site.

This.

Some Wonk2011-01-20 13:35

Eric B.:

George:

Under the spreading B11CFee,
I soldU and you soldB.
There we lie and there EscB,
under the spreading R5Fee.

Nice poem, comrade.

No. Oceania has always been at war with Eurasia. We are allies with Eastasia.

oosterwal2011-01-20 21:39

trwtf:

Isn't it supposed to be a vase?

shotcircut:

Isn't all VBA?

No, some VBA is supposed to be two faces. And some is supposed to be a duck, and some is supposed to be a rabbit.

I'd bet pi/e shares of that company's stock that it's a graph of the company's stock price during Trent's tenure supporting the freight calculator code.

And of course on a line like the last one shown, only the LAST variable is strongly typed, the rest are all Variants.

*2011-01-23 21:39

What design pattern is this?

darklydrawl2011-01-24 17:57

hahaha, yeah, that was my thought as well. Mostly variants. that is going to cause some pain...

Design Pattern2011-01-25 09:41

cindy:

A Lange & Sohne watches

Audemars Piguet watches

Ulysse Nardin watches

Worse than Failure: Using Akismet!

Shinobu2011-02-05 05:40

ABT:

the real WTF is that in VBA (unlike VB proper), the last variable is the only one that gets assigned the variable type passed. For instance, in this line:
Public PrmID, ImptID As Long
only ImptID is cast as a Long. PrmID is cast as the default -- a memory clogging 'Object' type.

That's false on two counts.
1) Variables without As clause are considered Variants, not Objects. The difference is huge, for example, if you have this declaration: ‘Dim A, B As Object’ then ‘IsEmpty(B)’ will be False, while ‘A Is Nothing’ will yield a run-time error: Object required.
2) This is true not just in VBA, but also in VB proper, since they share the same engine. VB.net doesn't have Variants so they had to change it some way or another and the decision was taken to make it behave like the C family.