• The Bytemaster (unregistered) in reply to pinkduck
    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.
  • (cs) in reply to sprezzatura
    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?

  • (cs) in reply to NutDriverLefty
    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.

  • Englebart (unregistered) in reply to bikeoid

    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.

  • (cs) in reply to frits
    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?
  • trwtf (unregistered) in reply to Englebart
    Englebart:
    P.S. The Easter island bug was in the sparse island vegetation.

    ftfy

  • benmurphyx (unregistered) in reply to The Bytemaster

    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.

  • trwtf (unregistered) in reply to boog
    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.

  • VB6slave (unregistered) in reply to The Bytemaster
    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

  • (cs) in reply to trwtf
    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).

  • Peter (unregistered) in reply to sprezzatura
    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.
  • Alfred (unregistered)

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

  • Gunslinger (unregistered) in reply to boog
    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.

  • (cs) in reply to Gunslinger
    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.

  • (cs) in reply to Lewis
    Lewis:
    Twas brillig, and the soldZ TickerTal1s, Did Geta1ID and GubrU in the wabe: All Post3 were the PosandAllowd, And the RftUpPat2 GubrA
    That... that is amazing.

    It all makes sense, now.

  • (cs)

    I prefer Haiku compliance in mass variable declarations! (and in HTML)

  • Eric B. (unregistered) in reply to George
    George:
    Under the spreading B11CFee, I soldU and you soldB. There we lie and there EscB, under the spreading R5Fee.

    Nice poem, comrade.

  • (cs)

    Might be beautiful, but maintainability: VOID

  • Enlightened One (unregistered)

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

    What an incredible breakthrough in software design !

  • (cs) in reply to Gunslinger
    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.

  • (cs) in reply to Dr.Evil
    Dr.Evil:
    I see it, it's a sailboat!
    No, it's a schooner you idiot.
  • junior (unregistered) in reply to Jaime
    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&
    
  • Cheong (unregistered)

    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...

  • Steve (unregistered) in reply to My name

    It's a longneck beer bottle.

  • Steve (unregistered) in reply to My name
    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.

  • ABT (unregistered)

    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
  • (cs)

    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.

  • (cs)

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

  • Sudo (unregistered)

    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.

  • m (unregistered)

    In fact it's a Rorschachtest for code monkeys.

  • Shooey (unregistered)

    Ah, the flow of a software project.

  • Shooey (unregistered)
    a module named simply "Variables"
    I wonder what the other modules were called. "Functions" and "Macros"?
  • Anonymous (unregistered)

    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

  • anon (unregistered) in reply to Phlip
    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.
  • Brendan (unregistered) in reply to Anonymous
    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 Jr (unregistered) in reply to Iron fisted bit flipper
    Iron fisted bit flipper:
    This technique takes software crapmanship to a whole new level.

    FTFY

  • Larry David Jr (unregistered) in reply to Brendan
    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.

  • rd (unregistered) in reply to frits

    Please! Seek psychiatric help NOW!

  • (cs) in reply to rd
    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.

  • (cs) in reply to boog
    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).

  • Richard@Home (unregistered)

    Reminds me of this: http://www.geeksaresexy.net/2009/09/01/a-hidden-gem-in-html/

  • Tony (unregistered)

    Wonder if this was the intent, or just what I see in it:

    http://www.nationalgeographic.com/history/ancient/images/sw/easter-island-head-289121-sw.jpg

  • itsme (unregistered)

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

  • (cs) in reply to sprezzatura
    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.
  • Pyrexkidd (unregistered) in reply to sprezzatura
    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?

  • (cs) in reply to SCSimmons
    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.

  • YousaidtomeBear (unregistered)

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

    Whhooooooo!

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

    Ahhhh! Aooh!

  • Anonymous (unregistered) in reply to sprezzatura
    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.
  • (cs) in reply to sprezzatura
    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#.

  • (cs) in reply to Anonymous
    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.

Leave a comment on “Feng Shui”

Log In or post as a guest

Replying to comment #:

« Return to Article