Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

890636 Posts in 33508 Topics- by 24748 Members - Latest Member: CherrySlug

June 17, 2013, 08:40:36 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Post if you just laughed at your code.
Pages: 1 ... 9 10 [11] 12 13 ... 29
Print
Author Topic: Post if you just laughed at your code.  (Read 37280 times)
Mikademus
Level 10
*****


The Magical Owl


View Profile
« Reply #150 on: December 16, 2011, 07:33:18 AM »

My coding problem would be trying to follow the simple rule : less code is better.

This would make me try to squeeze way too much into a single line, everything in a single file.

You can imagine that more compressed does not necessarily mean less code but it certainly means less readable and less reusable.

I am trying to cure myself of this disease but there's certainly no quick way.


Keep telling yourself that readability is key, not compactness. Eventually your brain will re-learn.

Create a set of strict and exact rules you try to keep. F.i. two of mine are that classes declarations should have three blank lines between them and there is always two linefeeds above a scope keyword and one below.

Code:
class Example1
{
    private:

        void method1();
        void method2();
        void method3();
        void method4();


    public:

        void method5();
        void method6();
        void method7();
};



class Example2
{
};



class Example3
{
};

Also, while not as quantifiable, try to enforce that only things logically belonging together should not have linefeeds between lines.

Code:
void Function()
{
    DoTypeAThing_step1();
    DoTypeAThing_step2();
    DoTypeAThing_step3();

    DoTypeBThing_step1();
    DoTypeBThing_step2();
}

Try to keep things only of the same level of abstraction/granularity in the same function. This will mean you will start to compose more functions. This is OK, and good.

Code:
void BadFunction()
{
    MakeBreakfast();
    SeasonPancakes();
    for (Food::iterator i = food.begin(); i != food.end(); ++i)
    {
        if (!i->tooHot())
            i->eat();
    }
}



void GoodFunction()
{
    MakeBreakfast();
    SeasonPancakes();
    EatFood();
}

These rules introduced strictness, space and logical structure to your code and helps enormously with readability.
Logged

\\\"There\\\'s a tendency among the press to attribute the creation of a game to a single person,\\\" says Warren Spector, creator of Thief and Deus Ex. --IGN<br />My compilation of game engines for indies
Serapth
Level 2
**


View Profile
« Reply #151 on: December 17, 2011, 06:54:40 PM »

I code in a very similar style, but oddly enough, that extra newline around public: would drive me to drink!  It just screams at me, annoys me, whisper in my ear to kil... err, I've said too much.


Logged
J. R. Hill
Level 10
*****


The perfect farmer's tan.


View Profile WWW Email
« Reply #152 on: December 17, 2011, 07:03:43 PM »

I code without line-breaks.
Logged

DareM
Level 0
***



View Profile WWW Email
« Reply #153 on: December 18, 2011, 03:03:46 AM »


Keep telling yourself that readability is key, not compactness. Eventually your brain will re-learn.

Create a set of strict and exact rules you try to keep. F.i. two of mine are that classes declarations should have three blank lines between them and there is always two linefeeds above a scope keyword and one below.

These rules introduced strictness, space and logical structure to your code and helps enormously with readability.

I very much agree with your desire for code structure. A developer blogged about it recently how the rules, no matter how simple and mundane, let you also spend more brain power on the problem itself and not text spacing, formatting, etc...

And as you mentioned it helps with readability. At the end of the day, details on formatting rules are not as important as having them and sticking to them.

Logged

Altitude0 - Arcade Plane Racing for Windows PC
http://www.altitude0.com
Gauss Jordan
Level 2
**


This world!


View Profile WWW Email
« Reply #154 on: December 27, 2011, 11:36:32 AM »

Found this comment in some old inverse kinematics code of mine:
Code:
//Trigonometry FTW! Is complex. Won't explain.

Younger Gauss, I am disappoint. Lips Sealed

Regards,
Future Gauss
Logged

Lefty-concepty, righty-pixley, but bothey programmey.
pixhead
Level 4
****


fish_master57@hotmail.com
View Profile Email
« Reply #155 on: April 23, 2012, 03:33:51 PM »

Reviving this thread for a little gem I just found

Code:
if(newLine)
   newLine = !newLine
  Giggle
Logged

"Games are made by artists, so to not consider them art is an insult to the artists who work on them." - Some guy on IGN.
Xienen
Level 2
**


Greater Good Games


View Profile WWW Email
« Reply #156 on: April 24, 2012, 12:28:39 PM »

Reviving this thread for a little gem I just found

Code:
if(newLine)
   newLine = !newLine
  Giggle

Haha, we had a programmer write a line like that during a programming test to see if he should keep his job.  We then gave him a chance to redeem himself, thinking it was an honest mistake.  When he was unable to understand why that was wasteful, he was promptly terminated.  He was a really good friend of mine, so I really didn't want him to get fired.  He's since moved away from programming to be a millionaire starting multiple businesses, so it all worked out in the end =)
Logged

Owner/Programmer at Greater Good Games makers of Break Blocks
Currently developing It Hungers(Unity) and Swipe Attack(UDK)
mokesmoe
Level 10
*****



View Profile Email
« Reply #157 on: April 25, 2012, 02:02:34 AM »

Yeah, it should obviously be:
Code:
if(newLine > 0)
   newLine = newLine ^^ 1
Logged
Eigen
Level 8
***


Jebus backups.


View Profile WWW
« Reply #158 on: April 25, 2012, 02:39:25 AM »

Looking trough some of my old code:

Code:
some class
{
    // Getters
     * bunch of methods *

    // Setters
    * bunch of methods *

    // Bedwetters. Hilarious, I know.
}
Logged

KeeWeed
Level 0
**



View Profile WWW Email
« Reply #159 on: April 25, 2012, 04:37:51 AM »

Reviving this thread for a little gem I just found

Code:
if(newLine)
   newLine = !newLine
  Giggle

Beautiful.
Logged

Azure Lazuline
Level 2
**



View Profile WWW
« Reply #160 on: April 25, 2012, 11:02:35 PM »

So I'm working on a team project in C#, and recently while looking through it I found a file "Samuel_P_Fluffernutter.cs". Inside the file is class Samuel_P_Fluffernutter which is completely empty.

I don't know why I find this so amusing.
Logged

Copy Kitty - a platformer/shooter with 200 weapons! Blow up robots and destroy the world!
KeeWeed
Level 0
**



View Profile WWW Email
« Reply #161 on: April 26, 2012, 02:39:50 PM »

I had to pick up a project of a colleague of mine, and there I found a class called "DoNotTouch"

...and I'm not exactly sure what he means with that Wink
Logged

Geti
Level 10
*****



View Profile WWW
« Reply #162 on: April 26, 2012, 06:33:06 PM »

Looked over the protorts source. It's amazing how much you learn in a few years (that was when I decided I wanted to learn to code and just sat down with lua and tried to make stuff.)
Logged

Hedgehodg
Level 1
*


...


View Profile Email
« Reply #163 on: April 28, 2012, 12:00:06 AM »

Does it count as code if I am writing an essay and accidentally put a semicolon instead of a full stop at the end of each sentence :D  Shrug
Logged

Previously known as "darestium"...
Xecutor
Level 1
*


View Profile Email
« Reply #164 on: April 28, 2012, 05:34:30 AM »

Code:
  if(ptr=!NULL)return ptr;
Nice NULL check, yeah...
Logged
Pages: 1 ... 9 10 [11] 12 13 ... 29
Print
Jump to:  

Theme orange-lt created by panic