10 Replies - 1093 Views - Last Post: 19 November 2013 - 07:39 AM Rate Topic: -----

#1 alapee  Icon User is online

  • Stressed Out Programmer

Reputation: 133
  • View blog
  • Posts: 1,826
  • Joined: 24-October 13

Convulated Coding

Posted 14 November 2013 - 12:29 PM

So I was reading through the C# / C+-+ Challenges and came across the most horrible coding thread and I had previous read up on obfuscation and came up with a horrible Idea. (Pardon me if I posted this the wrong area).
The Idea is what is the worse code I could make that still worked. So I started off with a decent code practice (not the best because I am only a decent programmer)[this was done in vb.net] and then convoluted it to an evil version.

Then I thought what is the most horrible code that other people could make with the simple criteria of 1 button, 1 label, and 1 text box. I so decided to put the challenge out in the horrible coding area.

Here is my original coding:
Private Sub frmMainbttnGenerate_Click()
	dim strInformationFromfrmMaintbInput as string  =  frmMain.tbInput.text
	dim iLoopInteger as integer = 0
	try
	for iloopinteger =0 to 26
		if iloopinteger mod 2 then
			strInformationFromfrmMaintbInput = trim(mid(strInformationFromfrmMaintbInput,iloopinteger,len(strInformationFromfrmMaintbInput)))
		else
			strInformationFromfrmMaintbInput = trim(mid(strInformationFromfrmMaintbInput,1,len(strInformationFromfrmMaintbInput))
		end if
	next iloopinteger 
	frmMain.lblOutput.text = strInformationFromfrmMaintbInput
	catch ex as exception
		msgbox ex.tostring
	finally
		strinformationfromfrmmainbinput = string.empty 
	end try
End Sub



Here is the same coding convulated:
Private Sub b_click()
	dim s as string  =  f.t.text
	dim i as integer = 0
	on Error goto Errortext
	for i =0 to 26
		if i mod 2 then
			s = trim(mid(s,i,len(s)))
		else
			s = trim(mid(s,1,len(s))
		end if
	next i1 
	f.l.text = s
        ExitHere:
            s = string.empty 
            exit sub
	ErrorText:
	  msgbox (err.tostring)
          goto Exithere
End Sub



Now can anyone do better? (I mean worse)

This post has been edited by alapee: 14 November 2013 - 12:30 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Convulated Coding

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4333
  • View blog
  • Posts: 12,128
  • Joined: 18-April 07

Re: Convulated Coding

Posted 14 November 2013 - 01:13 PM

This seems to be a bit counterproductive doesn't it? Why practice making bad code? Sure you could make the argument that by working to make bad code you learn to make better code but I am the belief that if you just practice good coding from the beginning you won't be making bad code.

It is like practicing ride a bicycle. Why practice crashing? Unless you are learning how to properly protect yourself???

*shrugg*
Was This Post Helpful? 0
  • +
  • -

#3 alapee  Icon User is online

  • Stressed Out Programmer

Reputation: 133
  • View blog
  • Posts: 1,826
  • Joined: 24-October 13

Re: Convulated Coding

Posted 14 November 2013 - 01:20 PM

Boredom.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3478
  • View blog
  • Posts: 11,818
  • Joined: 12-December 12

Re: Convulated Coding

Posted 14 November 2013 - 01:47 PM

I see enough horrible coding in these forums :whistling:
Was This Post Helpful? 0
  • +
  • -

#5 alapee  Icon User is online

  • Stressed Out Programmer

Reputation: 133
  • View blog
  • Posts: 1,826
  • Joined: 24-October 13

Re: Convulated Coding

Posted 14 November 2013 - 01:54 PM

I agree the andrew there are some bad posts (i am even part of some of them) but it is the learning process, isn't it?
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3478
  • View blog
  • Posts: 11,818
  • Joined: 12-December 12

Re: Convulated Coding

Posted 14 November 2013 - 02:04 PM

Well, to clarify, I wasn't thinking about noobs whose code we can expect to be naive. As you say, part of the learning process. I was thinking more about those who don't study or follow advice. Hatchet-jobs (copy-paste merchants).

But anyway, it was just a passing comment ;)
Was This Post Helpful? 0
  • +
  • -

#7 alapee  Icon User is online

  • Stressed Out Programmer

Reputation: 133
  • View blog
  • Posts: 1,826
  • Joined: 24-October 13

Re: Convulated Coding

Posted 14 November 2013 - 02:19 PM

Why not use this an example of how not to code, the proper way to code it? An opportunity not taken to teach properly is an opportunity missed.
Was This Post Helpful? 0
  • +
  • -

#8 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,466
  • Joined: 29-May 08

Re: Convulated Coding

Posted 15 November 2013 - 06:25 AM

The thing about creating convoluted code is you have to open your mind to non-standard and unexpected ways of doing things.
Like my implementation of bounds checks using operators.
Was This Post Helpful? 0
  • +
  • -

#9 alapee  Icon User is online

  • Stressed Out Programmer

Reputation: 133
  • View blog
  • Posts: 1,826
  • Joined: 24-October 13

Re: Convulated Coding

Posted 15 November 2013 - 07:37 AM

True you have to open your mind is the key word and by doing so we might find new and better ways to code something. That is why we don't code the same way we did in the beginning.
Was This Post Helpful? 0
  • +
  • -

#10 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 673
  • View blog
  • Posts: 2,960
  • Joined: 03-December 12

Re: Convulated Coding

Posted 18 November 2013 - 05:05 PM

Not to mention obfuscation challenges are on the menu

types of challenges

I would prefer to learn best and more maintainable code before how to make the worst code work, which I agree is far worse when you are fixing an "experts masterpiece"
Was This Post Helpful? 0
  • +
  • -

#11 alapee  Icon User is online

  • Stressed Out Programmer

Reputation: 133
  • View blog
  • Posts: 1,826
  • Joined: 24-October 13

Re: Convulated Coding

Posted 19 November 2013 - 07:39 AM

So why not turn this into, can you coded it better?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1