One of the things I find myself doing occasionally is looking at my old code. When you have over a decade of source code and projects that you’ve worked on, you can, perhaps ironically, learn a lot by reading your own code. When you read your old work, you really should seldom be impressed- that’s not a good thing, by any means, because it means that you have become a better developer in the meantime. It’s when you find your past self to be incredibly skilled even relative to yourself now that you may need to consider that you’ve stagnated. Following this, I thought I would write about some old code I wrote, provide it, and point out where I went wrong and where I went right.
As an example, pretty much my first program that did anything useful was a small Visual Basic 2.0 program, which allowed the selection of colours for HTM LBody tags (the old BGCOLOR, TEXT, LINK, ALINK, VLINK, etc settings), this, despite working with 16-color graphics. At some point, I became rather- obsessed- with gradients. Styles, colours, easing…. the signs of insanity were all there. Thus was the start of my first “Module” for code-sharing- “GRAPHICS.BAS”.
GRAPHICS.BAS ballooned in size as I basically just slapped all sorts of functions into it. the seed was “paintfrm” which itself became rather ridiculous. The comments make me incredibly glad that I was not regularly posting on the Internet at those times, and interestingly I see the symptoms today, where somebody who is 15,16, etc. seems to think they have it all figured out and their silly little program/routine should be heralded as creating a new era for humankind- but that is another story altogether. Just glad that my early contributions to the world wide web are difficult to associate with me personally, as they are quite embarassing.
Despite them being somewhat cringey, I kept the comments in the function intact. This is a Visual Basic routine, and it is rather long.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 | Sub paintfrm(ByVal Color1 As Long, _              ByVal Color2 As Long, _              Formex As Object, _              ByVal typer As GradientTypes, _              Optional ByVal Cycles As Integer = 1, _              Optional Drawmode As Integer = 13, _              Optional Degree As Double = 1, _              Optional SchemeMode As Integer = 0, _              Optional ByVal Numsides As Double = 8, _              Optional Sangle As Double = 0, _              Optional EndAngle As Double = 0)     ' SO FRIGGIN TOTALLY Created By Michael Burgwin     'about the only procedure that I just wanted to make.     'Other procedures I made were inspired by seeing crappy versions     'of other procedures perform the task in a brute force(crappy) way.     'You shouldn't find more then three lines in a row that do not refer to a property     'that are the same as any other three lines of code that you can find.     '+------------------------------------------------------------+     'PAINTFRM     'Arguments:     'Color1   The First Color.     'Color2   The Second Color.     'Formex   The Object To draw On.     '          If the Object has A Dc and A scaleWidth and Scaleheight, it should work.     'typer   'Enumerated Constant that decides which type of     '          gradient to Draw.     'Cycles    'Number of cycles     ' Drawmode 'drawmode to use.     'degree    'determines the speed the Colors gradate     'schemeMode  'determines the Mode of change.     '                0=RGB     '               1=CMY     '               2=HLS     'only really documented procedure.     'uses LineTo with Windows API, much faster then VB method.     Dim StartX!, startY!, r!, EndX!, EndY!     Dim TP          As PointAPI     Dim AroundP     As PointAPI     Dim Cent        As Single     Dim PAccum      As Double     Dim dummy       As Long, pointuse As PointAPI     Dim formof      As Form, UseHwnd As Long     Dim Rectuse     As RECT     Dim StAngle     As Double     Dim Bitcheck    As BITMAP     Dim oldmode     As Integer     Dim OldHeight   As Single     Dim oldwidth    As Single     Dim NewBit      As Long     Dim R1          As Double, G1 As Double, B1 As Double, I As Integer     Dim H!(1), l!(1), Sat!(1), C!(1), M!(1), Ye!(1)     Dim HA!, LA!, SA!, CA!, MA!, ya!     Dim Y           As Double, X As Double     Dim formXscale  As Single     Dim formYscale  As Single     Dim CenterX     As Single, CenterY As Single     Dim spiralX     As Single, spiralY As Single     Dim spiralwidth As Single, tohdc As Long     Dim LOOPS       As Long, s As Integer, lastI As Integer     Dim typeobj     As String     Dim objgood     As Boolean, UseColor As Long     On Error Resume Next     oldmode = Formex.ScaleMode     OldHeight = Formex.ScaleHeight     oldwidth = Formex.ScaleWidth     Cent = 255     'ok, get the object DC bitmap.     If typer = 4 Then Cycles = Cycles + 1     'we Will cheat, and Copy the two bitmaps.     tohdc = Formex.hdc     Formex.FillStyle = vbSolid     Dim TX1!, TX2!, TX3!, TY1!, TY2!, Ty3!     Dim XT(0 To 5) As Single, YT(0 To 5) As Single     'Dim R As Double     Dim G          As Double     Dim b          As Double     Dim R2         As Double     Dim G2         As Double     Dim B2         As Double     r = breakColor(Color1, 0)     G = breakColor(Color1, 1)     b = breakColor(Color1, 2)     R2 = breakColor(Color2, 0)     G2 = breakColor(Color2, 1)     B2 = breakColor(Color2, 2)     H(0) = hlsfromlong(Color1, 0)     H(1) = hlsfromlong(Color2, 0)     l(0) = hlsfromlong(Color1, 1)     l(1) = hlsfromlong(Color2, 1)     Sat(0) = hlsfromlong(Color1, 2)     Sat(1) = hlsfromlong(Color2, 2)     C(0) = CMYfromlong(Color1, 0)     C(1) = CMYfromlong(Color2, 0)     M(0) = CMYfromlong(Color1, 1)     M(1) = CMYfromlong(Color2, 1)     Ye!(0) = CMYfromlong(Color1, 2)     Ye!(1) = CMYfromlong(Color2, 2)     HA = H(0)     LA = l(0)     SA = Sat(0)     CA = C(0)     MA = M(0)     ya = Ye(0)     Call Formex.object.Add("PictureBox", "PicTmp")     'no need to regenerate or draw on form if minimized.     'It also causes an Illegal Function call error.     ' I'd Clear the Form/Object, but What if they want to acheive the affect of     'a gradential Picture? with Drawmode, etc.     R1 = r     G1 = G     B1 = b     '^saves first Color  to local variables     Formex.AutoRedraw = True     '^Not necessary, but particularly a good idea.     If Cycles < = 0 Then Cycles = 1     lastI = 0     With Formex                                                     'Form passed to procedure.         .ScaleMode = 3                                                   'pixels         .DrawWidth = 2         If Drawmode = 0 Then Drawmode = 13         .Drawmode = Drawmode                                                    'copy pen         .DrawWidth = 15     End With     If Formex.ScaleWidth > Formex.Width Then         Formex.ScaleWidth = Formex.Width     End If     If Formex.ScaleHeight > Formex.Height Then         Formex.ScaleHeight = Formex.Height     End If     'Selects which value for the gradient.     'Explore the possibilities. 0 through 14 are Valid.     formXscale = Formex.ScaleWidth     formYscale = Formex.ScaleHeight     CenterX = Formex.ScaleWidth / 2     CenterY = Formex.ScaleWidth / 2     AroundP.X = CenterX     AroundP.Y = CenterY     StAngle = Sangle     Select Case typer         Case 0                                                    'horizontal             Formex.DrawWidth = (Formex.ScaleHeight / 255) + 1             For s = 1 To Cycles                 For I = lastI To lastI + (255 / Cycles)                     pointuse.X = 0                     pointuse.Y = Y                     Formex.FillColor = UseColor                     Formex.FillStyle = vbSolid                     Formex.ForeColor = UseColor                     'formex.Line (0, y)-(formYscale, y + 2), UseColor                     'dummy = MoveToEx(Formex.hdc, Formex.ScaleWidth * Screen.TwipsPerPixelX, Y, pointuse)                     pointuse.X = Formex.ScaleWidth * Screen.TwipsPerPixelX                     pointuse.Y = Y                     'we now that the X and Y coordinates are                     '(formex.scalewidth*screen.twipsperpixelX,Y)                     'first, get Theta                     'either is Non zero, Rotate!                     dummy = MoveToEx(Formex.hdc, 0, pointuse.Y, TP)                     dummy = LineTo(Formex.hdc, pointuse.X, pointuse.Y)                     'secret formulae. hehe!                     GoSub changeColor                     Y = Y + Formex.ScaleHeight / 255 _                                               'add two to Y-Axis value.                 Next I                 lastI = I             Next s         Case 1                                                   'vertical             Formex.DrawWidth = (Formex.ScaleWidth / 255) + 1             For s = 1 To Cycles                 For I = lastI To lastI + (255 / Cycles)                     pointuse.Y = 0                     pointuse.X = Y                     Formex.FillColor = UseColor                     Formex.FillStyle = vbSolid                     Formex.ForeColor = UseColor                     'formex.Line (0, y)-(formYscale, y + 2), UseColor                     'dummy = MoveToEx(Formex.hdc, Formex.ScaleWidth * Screen.TwipsPerPixelX, Y, pointuse)                     dummy = MoveToEx(Formex.hdc, Y, 0, pointuse)                     dummy = LineTo(Formex.hdc, Y, Formex.ScaleWidth * _                             Screen.TwipsPerPixelY)                     'secret formulae. hehe!                     GoSub changeColor                     Y = Y + Formex.ScaleWidth / 255 _                                              'add two to Y-Axis value.                 Next I                 lastI = I             Next s         Case 2                                                   'diagonal             Formex.DrawWidth = 10             For s = 1 To Cycles                 For I = lastI To lastI + 255 / Cycles                     Formex.ForeColor = UseColor                     dummy = MoveToEx(Formex.hdc, X, 0, pointuse)                     'Formex.Line (X, 0)-(0, X), UseColor                     dummy = LineTo(Formex.hdc, 0, X)                     GoSub changeColor                     X = X + Sqr(2) * (Sqr(Formex.ScaleWidth ^ 2 + Formex.ScaleHeight ^ _                             2)) / 255                 Next I             Next s         Case 3                                                   'circular             Dim X1        As Double, Y1 As Double, X2 As Double, Y2 As Double             Dim centerout As Double             'Formex.ScaleWidth = 255 * Sqr(2)             'Formex.ScaleHeight = Formex.ScaleWidth             Formex.ScaleMode = 3             Formex.DrawWidth = 1             centerout = (Sqr(((Formex.ScaleWidth / 2) ^ 2) + ((Formex.ScaleHeight / 2) ^ _                     2))) * 1.25             X1 = -centerout * 0.5             Y1 = -centerout * 0.5             X2 = Formex.ScaleWidth + (centerout * 0.5)             Y2 = Formex.ScaleHeight + (centerout * 0.5)             'X2 = Formex.ScaleWidth + (Formex.ScaleWidth / 255)             '          X1 = -Formex.ScaleWidth / 255             '          Y1 = -Formex.ScaleWidth / 255             '          Y2 = Formex.ScaleHeight             For s = 1 To Cycles + 3                 For I = lastI To lastI + ((centerout) / Cycles)                     'Formex.Line (X1, Y1)-(X2, Y2), UseColor, BF                     Formex.DrawStyle = vbSolid                     Formex.Drawmode = Drawmode                     Rectuse.Bottom = Y2                     Rectuse.Top = Y1                     Rectuse.Left = X1                     Rectuse.Right = X2                     On Error GoTo 0                     Formex.DrawStyle = vbSolid                     Formex.FillColor = UseColor                     Formex.ForeColor = UseColor                     dummy = Ellipse(Formex.hdc, Rectuse.Left, Rectuse.Top, _                             Rectuse.Right, Rectuse.Bottom)                     X1 = X1 + (Formex.ScaleWidth / 255 / 2)                     Y1 = Y1 + (Formex.ScaleHeight / 255 / 2)                     X2 = X2 - (Formex.ScaleWidth / 255 / 2)                     Y2 = Y2 - (Formex.ScaleHeight / 255 / 2)                     If X1 >= X2 Or Y1 >= Y2 Then Exit Sub                     GoSub changeColor                     'Formex.Refresh                 Next I                 lastI = I             Next s         Case 4                                                     'square             Formex.ScaleWidth = 255 * Sqr(2)             Formex.ScaleHeight = Formex.ScaleWidth             Formex.ScaleMode = 3             Formex.DrawWidth = 1             centerout = Sqr(((Formex.ScaleWidth / 2) ^ 2) + ((Formex.ScaleHeight / 2) ^ _                     2))             X1 = -centerout * 0.5             Y1 = -centerout * 0.5             X2 = Formex.ScaleWidth + (centerout * 0.5)             Y2 = Formex.ScaleHeight + (centerout * 0.5)             Formex.FillStyle = vbSolid             For s = 0 To Cycles + 1                 For I = lastI To lastI + ((centerout) / Cycles)                     Formex.FillColor = UseColor                     Rectuse.Bottom = Y2                     Rectuse.Top = Y1                     Rectuse.Left = X1                     Rectuse.Right = X2                     'Formex.Line (X1, Y1)-(X2, Y2), UseColor, BF                     Formex.FillStyle = vbSolid                     Formex.FillColor = UseColor                     Formex.ForeColor = UseColor                     Formex.DrawStyle = vbSolid                     Formex.Drawmode = Drawmode                     On Error GoTo 0                     dummy = Rectangle(Formex.hdc, Rectuse.Left, Rectuse.Top, _                             Rectuse.Right, Rectuse.Bottom)                     DoEvents                     X1 = X1 + 1                     Y1 = Y1 + 1                     X2 = X2 - 1                     Y2 = Y2 - 1                     If X1 >= X2 Or Y1 >= Y2 Then Exit Sub                     GoSub changeColor                     Formex.Refresh                 Next I                 lastI = I             Next s             Formex.Refresh         Case 5                                                   'circle (0,0)-out             With Formex                 .ScaleWidth = 255 / Sqr(2)                 .ScaleHeight = 255 / Sqr(2)                 centerout = 255                 lastI = centerout             End With             lastI = centerout             For s = 0 To Cycles                 For I = lastI To lastI - (255 / Cycles) Step -1                     GoSub changeColor                     Formex.FillColor = UseColor                     Formex.Circle (0, 0), I, UseColor                 Next I                 lastI = I             Next s         Case 6                                                   'circle (formex.scalewidth,0)-out             With Formex                 .ScaleWidth = 255 / Sqr(2)                 .ScaleHeight = 255 / Sqr(2)             End With             centerout = 255             lastI = centerout             For s = 0 To Cycles                 For I = lastI To lastI - (255 / Cycles) Step -1                     GoSub changeColor                     Formex.FillColor = UseColor                     Formex.Circle (Formex.ScaleWidth, 0), I, UseColor                 Next I                 lastI = I             Next s         Case 7                                                   'circle (formex.scalewidth,formex.scaleheight)-out             With Formex                 .ScaleWidth = 255 / Sqr(2)                 .ScaleHeight = 255 / Sqr(2)             End With             centerout = 255             lastI = centerout             For s = 0 To Cycles                 For I = lastI To lastI - (255 / Cycles) Step -1                     GoSub changeColor                     Formex.FillColor = UseColor                     Formex.Circle (Formex.ScaleWidth, Formex.ScaleHeight), I, UseColor                 Next I                 lastI = I             Next s         Case 8                                                   'circle (0,formex.scaleheight)-out             With Formex                 .ScaleHeight = 255 / Sqr(2)                 .ScaleWidth = 255 / Sqr(2)             End With             centerout = 255             lastI = centerout             For s = 0 To Cycles                 For I = lastI To lastI - (255 / Cycles) Step -1                     GoSub changeColor                     Formex.Circle (0, Formex.ScaleHeight), I, UseColor                 Next I                 lastI = I             Next s         Case 9                                                   'square from 0,0             With Formex                 .ScaleHeight = 255                 .ScaleWidth = 255             End With             centerout = 255             For s = 0 To Cycles                 For I = lastI To lastI + (255 / Cycles)                     GoSub changeColor                     Formex.Line (0, 0)-(255 - I, 255 - I), UseColor, B                 Next I                 lastI = I             Next s         Case 10                                                   'square from width,0             With Formex                 .ScaleHeight = 255                 .ScaleWidth = 255             End With             lastI = 0             centerout = 255             For s = 0 To Cycles                 For I = lastI To lastI + (255 / Cycles)                     GoSub changeColor                     Formex.Line (Formex.ScaleWidth, 0)-(I, 255 - I), UseColor, B                 Next I                 lastI = I             Next s         Case 11                                                   'width,height             With Formex                 .ScaleHeight = 255                 .ScaleWidth = 255             End With             lastI = 0             centerout = 255             For s = 0 To Cycles                 For I = lastI To lastI + (255 / Cycles)                     GoSub changeColor                     Formex.Line (Formex.ScaleWidth, Formex.ScaleHeight)-(I, I), _                             UseColor, B                 Next I                 lastI = I             Next s         Case 12                                                   '0,height             With Formex                 .ScaleHeight = 255                 .ScaleWidth = 255             End With             centerout = 255             lastI = 0             For s = 0 To Cycles                 For I = lastI To lastI + (255 / Cycles)                     GoSub changeColor                     Formex.Line (0, Formex.ScaleHeight)-(255 - I, I), UseColor, BF                 Next I                 lastI = I             Next s         Case 13                                                   'Sunburst outwards.             With Formex                 .ScaleHeight = 255                 .ScaleWidth = 255                 .DrawWidth = 5             End With             lastI = 0             CenterX = Formex.ScaleWidth / 2             CenterY = Formex.ScaleHeight / 2             For s = 0 To Cycles + 1.5                 Formex.DrawWidth = 2                 For I = lastI To lastI + (255 / Cycles)                     Formex.Line (CenterX, CenterY)-(I, 0), UseColor                     GoSub changeColor                     If I >= 255 Then Exit Sub                     Formex.Line (0, I)-(Formex.ScaleWidth, Formex.ScaleHeight - I), _                             UseColor                     Formex.Line (I, 0)-(Formex.ScaleWidth - I, Formex.ScaleHeight), _                             UseColor                     DoEvents                 Next I                 lastI = I             Next s         Case 14                                                   'PolyGonal-             'numsides will be used.             'simply have a Circle go from the Outside to the inside.             'probably the hardest.             Dim distx  As Double, disty As Double, aspect As Double, rootr As Double             Dim radius As Double, Q As Double             radius = 255             Formex.ScaleWidth = 401             Formex.ScaleHeight = 401             CenterX = Formex.ScaleWidth / 2             CenterY = Formex.ScaleHeight / 2             'rootr = Sqr(((formex.Width / 2) ^ 2) + ((formex.Height / 2) ^ 2)))             rootr = 255 / Sqr(2)             distx = Formex.Width - CenterX + (rootr / 2)             disty = Formex.Height - CenterY + (rootr / 2)             aspect = Formex.ScaleHeight / Formex.ScaleWidth             radius = 260             For s = 0 To Cycles                 For I = lastI - 5 To lastI + (255 / Cycles)                     Q = Q + 1                     Formex.Refresh                     DoEvents                     Formex.FillStyle = 0                     Formex.FillColor = RGB(r, G, b)                     If radius < = 0 Then Exit Sub                     StAngle = StAngle + ((EndAngle - Sangle) / 260)                     Call RegularPolygon(CenterX, CenterY, Formex, UseColor, Numsides, _                             StAngle, PI * 2, CLng(radius))                     GoSub changeColor                     radius = radius - 1                     If radius <= 0 Then Exit For                 Next I                 If radius <= 0 Then Exit For             Next s             Debug.Print Q         Case 15                                                   'Offset Circle.             'simply use the start angle to find out where to begin.             radius = Sqr((Formex.ScaleWidth ^ 2) + Formex.ScaleHeight ^ 2)             'determine the starting Coordinate.             StartX = 0             startY = Formex.ScaleHeight / 2             r = Formex.ScaleWidth / 2             'get theta             Theta = StartAngle             StartX = Sin(Theta) * r             startY = Cos(Theta) * r             'use this for the start value.             'get the ending value.             EndX = StartX + Formex.ScaleWidth             EndY = startY + Formex.ScaleHeight             For s = 0 To Cycles                 For I = lastI To lastI + (255 / Cycles)                     Formex.Circle (StartX + ((EndX - StartX) / Cycles), startY + ((EndY _                             - startY) / Cycles)), radius                 Next I             Next s     End Select     Formex.ScaleMode = oldmode     Formex.ScaleWidth = oldwidth     Formex.ScaleHeight = OldHeight     Formex.Refresh     Exit Sub changeColor:     Select Case SchemeMode         Case 0                                                   'RGB             If s Mod 2 = 0 Then                                                   'even number, go from Color2 to Color1                 r = r - (((R2 - R1) / (Cent / Cycles)) * Degree)                 If r > 255 Then r = 255                 If r < 0 Then r = 0                 G = G - (((G2 - G1) / (Cent / Cycles)) * Degree)                 If G > 255 Then G = 255                 If G < 0 Then G = 0                 b = b - (((B2 - B1) / (Cent / Cycles)) * Degree)                 If b > 255 Then b = 255                 If b < = 0 Then b = 0             Else                 r = r + (((R2 - R1) / (Cent / Cycles)) * Degree)                 If r > 255 Then r = 255                 If r < 0 Then r = 0                 G = G + (((G2 - G1) / (Cent / Cycles)) * Degree)                 If G > 255 Then G = 255                 If G < 0 Then G = 0                 b = b + (((B2 - B1) / (Cent / Cycles)) * Degree)                 If b > 255 Then b = 255                 If b < 0 Then b = 0             End If             UseColor = RGB(r, G, b)         Case 1             If s Mod 2 = 0 Then                                                   'even number, go from Color2 to Color1                 CA = CA - (((C(1) - C(0)) / (Cent / Cycles)) * Degree)                 If CA > 255 Then CA = 255                 If CA < 0 Then CA = 0                 MA = MA - (((M(1) - M(0)) / (Cent / Cycles)) * Degree)                 If MA > 255 Then MA = 255                 If MA < 0 Then MA = 0                 ya = ya - (((Ye!(1) - Ye!(0)) / (Cent / Cycles)) * Degree)                 If ya > 255 Then ya = 255                 If ya < = 0 Then ya = 0             Else                 CA = CA + (((C(1) - C(0)) / (Cent / Cycles)) * Degree)                 If CA > 255 Then CA = 255                 If CA < 0 Then CA = 0                 MA = MA + (((M(1) - M(0)) / (Cent / Cycles)) * Degree)                 If MA > 255 Then MA = 255                 If MA < 0 Then MA = 0                 ya = ya + (((Ye!(1) - Ye!(0)) / (Cent / Cycles)) * Degree)                 If ya > 255 Then ya = 255                 If ya < 0 Then ya = 0             End If             UseColor = CMY(CA, MA, ya)         Case 2             If s Mod 2 = 0 Then                                                   'even number, go from Color2 to Color1                 HA = HA - (((H(1) - H(0)) / (Cent / Cycles)) * Degree)                 If HA > 255 Then HA = 255                 If HA < 0 Then HA = 0                 LA = LA - (((l(1) - l(0)) / (Cent / Cycles)) * Degree)                 If LA > 255 Then LA = 255                 If LA < 0 Then LA = 0                 SA = SA - (((Sat(1) - Sat(0)) / (Cent / Cycles)) * Degree)                 If SA > 255 Then SA = 255                 If SA < = 0 Then SA = 0             Else                 HA = HA + (((H(1) - H(0)) / (Cent / Cycles)) * Degree)                 If HA > 255 Then HA = 255                 If HA < 0 Then HA = 0                 LA = LA + (((l(1) - l(0)) / (Cent / Cycles)) * Degree)                 If LA > 255 Then LA = 255                 If LA < 0 Then LA = 0                 SA = SA + (((Sat(1) - Sat(0)) / (Cent / Cycles)) * Degree)                 If SA > 255 Then SA = 255                 If SA < 0 Then SA = 0             End If             UseColor = HLS(HA, LA, SA)     End Select     Return End Sub | 
Just look at this. The hubris in the comment at the start. It uses a few other functions (regularPolygon, HLS, CMY) but those have the sort of implementation you would expect (dare I say, reasonable). What can we say about this function? Some obvious considerations come to mind for criticism:
It tries to do too much
14 special cases for special purpose gradients? Each of which interpret the actual parameters slightly differently? And it isn’t even an enumeration- it’s just a flat Integer value. To be fair to my former self I think I originally wrote it in VB2 which didn’t have enumerations, but nonetheless, it would have been possible to use Constants.
Variables are poorly named
I don’t even know what have of these do. what is SA? LOOPS? objgood? the XT! Array? Why do some of them declare their type with a type declaration character, while others declare their type specifically?
GOSUB…. RETURN
I mean… come on. Really? This isn’t Commodore BASIC, we can create new functions. What was I thinking
In my defense, this was before I learned about Object Oriented programming concepts and really before I learned anything about good design. Of course if you asked me back then I would have said I was a “good programmer” but I think this stuff shows that I would have been a liar to do so. Furthermore, this leaves one thinking.
I like to think I’m a capable programmer, but when I see my old code like this I always consider otherwise. It is notable that more recent programs (Like BCSearch) are really only annoying now because of the technology I used (VB6) and a few minor design decisions. If anything, they are often over-engineered.
One interesting approach is to try to be working on something where your skill level is that low. The goal being that in ten years you can look back and go “man, I barely knew how to use X, but now I consider all those trouble points trivial considerations”. It let’s you know that you’ve progressed.
Have something to say about this post? Comment!
