Bad Code Spawned from Ignorance

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
verysunshine
Veteran
Posts: 339
Joined: Wed Sep 24, 2014 5:03 pm
Organization: Wild Rose Interactive
Contact:

Bad Code Spawned from Ignorance

#1 Post by verysunshine »

Sometimes, we have bad code because we have a misconception about how things work, or because we use the first method we find to make something work when there are much better solutions available. Other times, we write bad code because we just don't know any better.

My current project required telling the player the date in a range from December of one year to January of the next. I accomplished this with four variables, one for the number of days since the start of the game, one for the number of the day that would be shown to the player, one for the month, and one for the year. This is definitely the wrong way to do things, and there are plenty of methods in the cookbook. The only reason I used this method was that I knew exactly when the start and end of the game would be, and the total time was short.

I also used single-character variables, mostly for character names. This works well because there are 6 characters total. There was an incident when this caused an amusing hiccup. V was being used for value in some example code, but it corresponded to a character name. Thankfully, that didn't break anything.

What are your instances of ignorantly bad code?

Build the basics first, then add all the fun bits.

Please check out my games on my itch.io page!

User avatar
Lord Hisu
Regular
Posts: 58
Joined: Sun Feb 11, 2018 2:31 am
Contact:

Re: Bad Code Spawned from Ignorance

#2 Post by Lord Hisu »

What's important is not to don't do bad code, because sometimes you don't really have a choice. When you're in a hurry, or when you start to work on another person project, or even when it "already works" that way and it will be a pain to start from scratch.

What's important is knowing the code is bad and keeping that on your mind, because the next time you see yourself starting to do bad code, you will remember that is better to do things in another way. Always search and ask if you don't know how to do things. And if you do know how to do something and is already in the middle of doing that bad code, believe me, it will be better if you start again.
verysunshine wrote: Tue Mar 13, 2018 5:12 pm What are your instances of ignorantly bad code?
I won't give you examples because I code a lot, so ignorantly bad code just happens when I'm learning something new (like Renpy, 2 months ago). But even then, the more you learn about coding, the easier it is to predict what these new things will be. I obviously do dumb things sometimes, but when I realize that I just start over - believe me, it is the best for your code.

Actually, my very first game was a BIG project, and it ended up being a lot more duct tape than any other thing. It worked, but the code itself was a mess.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Bad Code Spawned from Ignorance

#3 Post by Imperf3kt »

My bad habit is probably that I start by writing improper code. This is just what 'works', so I go with it.
From there, I'll look into ways to improve it or even replace parts of it with more efficient or recommended / compliant code.

By having something that works, even a hack, I find it easier to keep the end goal in sight. So in this way, bad coding practises can be useful.
Of course, it is a double edged sword - if you're too deep in, it may become impractical to "fix" the bad habit if its a pivotal part of your game.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Bad Code Spawned from Ignorance

#4 Post by trooper6 »

One bad habit I had when starting was that I came from Java and so I was writing getters and setters for every variable...and...you just don't really do that in Python.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

verysunshine
Veteran
Posts: 339
Joined: Wed Sep 24, 2014 5:03 pm
Organization: Wild Rose Interactive
Contact:

Re: Bad Code Spawned from Ignorance

#5 Post by verysunshine »

Lord Hisu wrote: Tue Mar 13, 2018 8:25 pm What's important is knowing the code is bad and keeping that on your mind, because the next time you see yourself starting to do bad code, you will remember that is better to do things in another way. Always search and ask if you don't know how to do things. And if you do know how to do something and is already in the middle of doing that bad code, believe me, it will be better if you start again.
That's why I said ignorantly bad code rather than just bad code. If you're not aware a problem is a problem, it's far harder to notice, let alone fix. Even if you're given a bit of code, if you don't know how it works you'll still make mistakes.

Build the basics first, then add all the fun bits.

Please check out my games on my itch.io page!

Post Reply

Who is online

Users browsing this forum: Google [Bot]