Jump to content

Unnecessary complicated code

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
Sometimes when I code something I suddenly realize how complicated I make the code to just make it shorter. Most of the time it happens when I'm writing out coordinates for drawing graphics depending on some variables. Does this happens to you too or do you often write lots of rows with simple code instead of few rows with very complicated code?


I made a very exaggerated code sample to show you how it could look like:

        Using Img As New Bitmap(500, 200), g As Graphics = Graphics.FromImage(Img)

            For i As Integer = 1 To 15

                g.FillRectangle(New SolidBrush(Color.FromArgb((i Mod 2 = 1) * (-255 / 15) * i, (i = 2 Or i = 5 Or i = 9) * -100, (i <> 3) * (-255 / 8) * Math.Ceiling(i / 2))), New Rectangle((i = 1) * -25 + (i = 2 Or i = 3) * -50 + (i = 4) * -125 + (i = 5) * -175 + (i = 6 Or i = 7) * -150 + (i = 8) * -225 + (i = 9) * -275 + (i = 10 Or i = 11) * -250 + (i = 12) * -325 Or (i >= 13 And i <= 15) * -350, (i = 1 Or i = 2 Or i = 4 Or i = 5 Or i = 6 Or i = 8 Or i = 10 Or i = 12 Or i = 13) * -25 + (i = 3 Or i = 7 Or i = 11 Or i = 15) * -100 + (i = 9) * -50 + (i = 14) * -62.5, (i = 2 Or i = 3) * -25 + (i = 13 Or i = 15) * -12.5 + 25, (i = 1 Or i = 4 Or i = 5 Or i = 8 Or i = 12) * -75 + (i = 9) * -25 + 25))

            Next

        End Using 

That 5 row code will create this image:

[ATTACH]3089[/ATTACH]

Attached Files



#2
marwex89

marwex89

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 10,720 posts
Have done that. It's just too easy to just cram computations together without thinking about readability at all.
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa