programing habits

This recent example says everything about empty lines, indents and namings:
Code:
void CMainWnd::OnPaint() 
{
	CPaintDC dc(this); 

	if (play)
	{
		CHARACTER *chr;
		POSITION pos=chars.GetHeadPosition();
		for (int i=0; i<chars.GetCount(); i++)
		{
			chr=&chars.GetNext(pos);
			dc.Ellipse(chr->loc.x-3, chr->loc.y-3, chr->loc.x+3, chr->loc.y+3);
		**
	** //play
**

I'm tempted to use short variable names, I always indent, sometimes I comment the end bracket if there's much code between. For single-statement if's I only indent, not use brackets. Also, I usually put empty lines to separate significantly differing code segments. I usually don't have a problem following a previously written program of mine after a while, but I should work on using more describing variable names when it comes to bigger projects. I usually write the code fast and let compiler point out the mistaken names and missing characters and all.
 
john_d said:
i use this program called notepad++

it helps me a lot with close and open brackets.. all i need to do is hilight a bracket ( close or open ) and the other bracket that is it suppose to be paired with will light up.. so that's basically a very good tool in recoding some of my old works or something

I used that for a while, its kind of like gedit on linux.
 
john_d said:
i use this program called notepad++

it helps me a lot with close and open brackets.. all i need to do is hilight a bracket ( close or open ) and the other bracket that is it suppose to be paired with will light up.. so that's basically a very good tool in recoding some of my old works or something
That's absolutely right :) I use notepad++ a lot, but I wish it had more php functions added, like odbc functions.
Anyways, that's something I can live with :tp:
 
Lady_Fu said:
That's absolutely right :) I use notepad++ a lot, but I wish it had more php functions added, like odbc functions.
Anyways, that's something I can live with :tp:
would love to see some of your works :p
 
A certain developer on here made a function in me excel then converted it to code and gave it to me. Since he converted it directly and knew exactly how it was laid out in excel he just named the variables A, B, C etc.. i have been coding in a LOT of languages for YEARS and i have to say thats the most obfuscated piece of crap i have ever seen in my LIFE! it looks like enigma or something! (its only 30 or so lines long! i cant even debug this thing)

I use tab indentation but usually convert it to 4space later, this makes it easier to indent etc but old editors and, particularly, unix developers tend to REALLY hate tabs. One or 2 spaces is simply too small to clearly see the indentation and if you actaully write 4 spaces per indent you end up writing 13 spaces instead of 12 or whichever which will be a total disaster if you ever try a language such as python, which is indentation dependant.

I put my opening braces on their own line but if there is only one line to execute in a block I put it on its own line (unless its a language like VB in which putting it on its own line requires you to put an "End If" on another line). Blank lines can also be very useful to make code readable and people should always ALWAYS use meaningful names for variables.

sometimes i use variable names with names like intSomeNumber, sometimes i use just plain someNumber etc, depending on the language.

I try and keep comments on their own lines and put a space between the comment keyword and its text (for example "' Some comment" or "// Some other comment"

some code of mine may look like this:
Code:
#include <iostream>
using namespace std;

int main()
{
    int intSomeNumber = 0;
    int* ptrSomeNumber = &intSomeNumber;

    for(int i = 0; i < 2; i++)
        (*ptrSomeNumber)++;

    // Better output something at some point
    cout << *ptrSomeNumber;

    if(intSomeNumber == *ptrSomeNumber)
    {
        cout << "This definately happened" << endl;
        return 0;
    **
    else
        return 1;
**

I know.. im weird.. but i find it makes my code incredibly readable for others :D

Also while people are talking about editors i HIGHLY reccomend one for windows called CRIMSON EDITOR (Homepage of Crimson Editor - Free Text Editor, Html Editor, Programmers Editor for Windows) It's by far the best editor I have ever seen, supports hundreds of languages, tabbed editing and a shedload of good features but remains lightweight, it is pretty reminiscent of gEdit but has a lot more features (hell you can save directly to ftp and use macros and it has auto intent and simple project support) and is for windows (theres an Open Source port i believe called Emerald Editor but i have never seen it actually used)
 
Last edited:
Hmm... I like to keep my code neat//easy to read but some what compact, and organized, indenting, using long veriable names so i know what they are later, etc.
 
john_d said:
would love to see some of your works :p

right now I'm coding Dios's Mu server website.. I was trying to code a site for car sales, but I quitted that project.. and there are a couple of projects in my head that I'll make true when I can find a time for them :tp:
 
i always use whitespace, never comments, my code is very dirty, i use a lot of code to do simple tasks in php and c++
i also dont type code like mysql queries, i just have a library of ones i made for all circumstances.

i hate elses and if's but use them alot
 
i suggest you all go linux way.. once you get teh hang of it, you never let down :) it's simply so neat and easy.
there you can use kate ( KDE Advanced Text Editor ), which has syntax highlighting and eeevery tool u need. believe me, it's worth it. Made my like a ton more easyer :D
 
i suggest you all go linux way.. once you get teh hang of it, you never let down :) it's simply so neat and easy.
there you can use kate ( KDE Advanced Text Editor ), which has syntax highlighting and eeevery tool u need. believe me, it's worth it. Made my like a ton more easyer :D

Linux editors make me want to poke my eyes in with a poolcue.
 
hihihi part of me wants to poke every linux wanna be guru in the eye... gez just because u use linux doesnt make u all powerful

This hasnt got any thing to do with this thread. Please burn. Anyway, when i code in pascal/delphi + c++, i try to make my code as neat as possible in everyway. I try to do things in the most simple + quickest but yet in a stable way. I don't really like to comment my applications source code much, maybe just like to remind me what values are supposed to be where and when and such like when using the inline assembely in both the Delphi and MSVC++ compiler.

Oh, also, it's best if you try to keep your code as neat and user friendly as possible, because if you write some software for a company and they can't read it, then you're going to have problems on your hands and things can go messy. :crash:
 
Back