Have you ever re-looked at your code and realized it was some piece of uttermost rubbish?

Mashiane

Expert
Licensed User
Longtime User
I' m like, what the hell was I thinking? This is absolute rubbish!! I think my brain had hit one of those ... "no longer thinking modes..." ha ha ha

B4X:
private Sub GetMarginPadding(varOffsets As String) As Map
    Dim m As Map = CreateMap("a":"", "x":"", "y":"", "t":"", "b":"", "l":"", "r":"")
    If BANano.IsUndefined(varOffsets) Or BANano.IsUndefined(varOffsets) Then Return m
    varOffsets = varOffsets.replace("-","|")
    varOffsets = varOffsets.replace(",","|")
    varOffsets = varOffsets.replace(";","|")
    varOffsets = varOffsets.replace("|",",")
    varOffsets = varOffsets.replace("?","")
    varOffsets = varOffsets.replace(" ","")
    varOffsets = varOffsets.trim
    
    '
    Dim ss As List = BANanoShared.StrParse(",", varOffsets)
    Dim a As String = ""
    Dim x As String = ""
    Dim y As String = ""
    Dim t As String = ""
    Dim b As String = ""
    Dim l As String = ""
    Dim r As String = ""

    '
    Select Case ss.Size
    Case 1
        a = ss.Get(0)
        a = BANanoShared.GetNumbers(a)
        If a.IndexOf("=") = 0 Then    a = "a=" & a
    Case 2
        a = ss.Get(0)
        x = ss.Get(1)
        a = BANanoShared.GetNumbers(a)
        x = BANanoShared.GetNumbers(x)
        '
        If a.IndexOf("=") = 0 Then a = "a=" & a
        If x.IndexOf("=") = 0 Then x = "x=" & x
    Case 3
        a = ss.Get(0)
        x = ss.Get(1)
        y = ss.Get(2)
        a = BANanoShared.GetNumbers(a)
        x = BANanoShared.GetNumbers(x)
        y = BANanoShared.GetNumbers(y)
            
    '
        If a.IndexOf("=") = 0 Then a = "a=" & a
        If x.IndexOf("=") = 0 Then x = "x=" & x
        If y.IndexOf("=") = 0 Then y = "y=" & y
    Case 4
        a = ss.Get(0)
        x = ss.Get(1)
        y = ss.Get(2)
        t = ss.Get(3)
        a = BANanoShared.GetNumbers(a)
        x = BANanoShared.GetNumbers(x)
        y = BANanoShared.GetNumbers(y)
        t = BANanoShared.GetNumbers(t)
            '
        If a.IndexOf("=") = 0 Then a = "a=" & a
        If x.IndexOf("=") = 0 Then x = "x=" & x
        If y.IndexOf("=") = 0 Then y = "y=" & y
        If t.IndexOf("=") = 0 Then t = "t=" & t
    Case 5
        a = ss.Get(0)
        x = ss.Get(1)
        y = ss.Get(2)
        t = ss.Get(3)
        b = ss.Get(4)
        '
        a = BANanoShared.GetNumbers(a)
        x = BANanoShared.GetNumbers(x)
        y = BANanoShared.GetNumbers(y)
        t = BANanoShared.GetNumbers(t)
        b = BANanoShared.GetNumbers(b)
            '
        If a.IndexOf("=") = 0 Then a = "a=" & a
        If x.IndexOf("=") = 0 Then x = "x=" & x
        If y.IndexOf("=") = 0 Then y = "y=" & y
        If t.IndexOf("=") = 0 Then t = "t=" & t
        If b.IndexOf("=") = 0 Then b = "b=" & b
    Case 6
        a = ss.Get(0)
        x = ss.Get(1)
        y = ss.Get(2)
        t = ss.Get(3)
        b = ss.Get(4)
        l = ss.Get(5)
        '
        a = BANanoShared.GetNumbers(a)
        x = BANanoShared.GetNumbers(x)
        y = BANanoShared.GetNumbers(y)
        t = BANanoShared.GetNumbers(t)
        b = BANanoShared.GetNumbers(b)
        l = BANanoShared.GetNumbers(l)

            '
        If a.IndexOf("=") = 0 Then a = "a=" & a
        If x.IndexOf("=") = 0 Then x = "x=" & x
        If y.IndexOf("=") = 0 Then y = "y=" & y
        If t.IndexOf("=") = 0 Then t = "t=" & t
        If b.IndexOf("=") = 0 Then b = "b=" & b
        If l.IndexOf("=") = 0 Then l = "l=" & l
    Case 7
        a = ss.Get(0)
        x = ss.Get(1)
        y = ss.Get(2)
        t = ss.Get(3)
        b = ss.Get(4)
        l = ss.Get(5)
        r = ss.Get(6)
        a = BANanoShared.GetNumbers(a)
        x = BANanoShared.GetNumbers(x)
        y = BANanoShared.GetNumbers(y)
        t = BANanoShared.GetNumbers(t)
        b = BANanoShared.GetNumbers(b)
        l = BANanoShared.GetNumbers(l)
        r = BANanoShared.GetNumbers(r)
            '
        If a.IndexOf("=") = 0 Then a = "a=" & a
        If x.IndexOf("=") = 0 Then x = "x=" & x
        If y.IndexOf("=") = 0 Then y = "y=" & y
        If t.IndexOf("=") = 0 Then t = "t=" & t
        If b.IndexOf("=") = 0 Then b = "b=" & b
        If l.IndexOf("=") = 0 Then l = "l=" & l
        If r.IndexOf("=") = 0 Then r = "r=" & r
    End Select
    '
    Dim sbdata As String = $"${a};${x};${y};${t};${b};${l};${r}"$
    Dim ssx As List = BANanoShared.StrParse(";", sbdata)
    For Each d As String In ssx
        Dim k As String = BANanoShared.MvField(d, 1, "=")
        Dim v As String = BANanoShared.MvField(d, 2, "=")
        m.Put(k, v)
    Next
    Return m
End Sub

This was nonsense!!! Does, it work? It was until I added .GetNumbers...
 

Sandman

Expert
Licensed User
Longtime User
Only every time I re-visit old code. There's this saying:

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

Let's just say I'm lucky I don't have a time-machine so I could travel back and strangle myself. That said, I do try to better myself and make future-me find my code at least acceptable.
 

rabbitBUSH

Well-Known Member
Licensed User
HEh HEh only when the comments are nonsense. ?

a friend of mine will always rewrite a program from scratch if he ever reads the code over again.
 

ilan

Expert
Licensed User
Longtime User
so many times. a few weeks ago I wanted to update an app because of the new admob policy. that app i made a long time ago and when I opened it and started updating some stuff I realized that it would be simpler for me to write the app again then trying to understand the code and why I did that like this. so I started a blank project and rewrite the app but this time much cleaner and cross-platform (b4x)
I am happy I did it!
 

ilan

Expert
Licensed User
Longtime User
Just curious, how long did it (roughly) take to write the original app? And how long the new version?

it was one of my first app (7 years ago) so then I took a few weeks or even more but the new version (for b4a and b4i) took me a few days. since I already know how the app should look like and what functions I need (and what functions I don't really need). I wanted to make also a b4i version of it anyway so it was a good reason to make it from scratch again. to tell you the truth, today I concentrate more on ios. I like working with b4i more than with b4a. especially games. i do make apps for android too, mostly cross-platform so they also run on ios but when it comes to games i prefer to do it on b4i. just working on something new right now. I hope I will release it soon and I will create a post in the share your creation forum ;)
 

Sandman

Expert
Licensed User
Longtime User
it was one of my first app (7 years ago) so then I took a few weeks or even more but the new version (for b4a and b4i) took me a few days
Yeah, that's what I suspected. :)

Thanks for sharing, and looking forward to your new creation!
 

Intelemarketing

Active Member
Licensed User
Longtime User
I look at my code and in AWE that it works so well !

That's because most of my code is a copy of the wonderful contributions you guys and Erel make on the forum ! Thank you for the GREAT CODE !

Litmus Test - Does it work - YES ? - Don't try to fix it. Does it work - NO ? - Let's fix it.

Merry Christmas everyone - And thank you all for your wonderful help this year!

I will be thinking of you in the North in -5 Degrees -(Shiver) while I eat my Christmas Turkey in 45 degrees in Australia !
 

Diceman

Active Member
Licensed User
I read an old user manual one time that I found lying around without looking at the cover, and thought, "Hey, this manual is funny and entertaining. It's well laid out and illustrated. A lot of work must have gone into it." Then I looked at the cover. It turns out I wrote it 20 years earlier. I got a chuckle out of that because I didn't realize my writing style had changed that much since then.
 

Diceman

Active Member
Licensed User
Merry Christmas everyone - And thank you all for your wonderful help this year!
I will be thinking of you in the North in -5 Degrees -(Shiver) while I eat my Christmas Turkey in 45 degrees in Australia !

It's still pretty mild up north. Cold isn't -5F. That's balmy shorts wearing weather. It doesn't get cold until windchill hits -40F. I worked at a mining operation years ago where every morning in January it was -40F without any wind. It would be a lot colder if there was a strong wind. They told me I was lucky to have gone home for Christmas because it dropped down to -54F during Christmas week. When the temperature gets down to -40F you can't turn off your diesel truck (even at night) because you won't be able to start it again until spring. ;) You'd have to tow to a heated garage and let it warm up while suffering the taunts of your buddies chiding you for being so dumb (which of course they've done themselves). My jeans would be frozen stiff in about 60 seconds after walking outside after being in a warm building. The old experiment is true, where you take a cup of boiling water and throw it up in the air and before it hits the ground it turns into ice crystals. Ah yes, the good old days of freezing my *ss off as a programmer.
 

rabbitBUSH

Well-Known Member
Licensed User
My jeans would be frozen stiff in about 60 seconds after walking outside after being in a warm building.
Weeeeeell someone Has to ask:
What about the CommandoWear?
That would make one a walking ../assuming one can at that those Temps/.. Cryobank in the AI* Industry.

A friend once left Canada It was negative 40c he disembarked here 18hours later it was positive 40.

Er maybe we should relook at the code of this thread :rolleyes:o_O

*(insemination)
 
Top