Code style suggestion

It is said that my code is pretty bad (poorly-formatted, hard to read code, and bad awful code logic etc...)
I chose VS2005 and I'm currently using the font face Verdana with its size : 8 (I think it's very small)
I usually work with lots of things and hence I have to reduce the size of command function names, make new function pointer link between structure and structure, and write down multiple group code in a line... I use the special code format, so I no need to worry about the code indentation. And, I always want my source to be short (as short as possible) by removing all tab characters and non-necessary space and enter characters, because it will make the sources IMO look easy,and I'll have more time to think up about new things...

But at any rate, I should know some advices and suggestions to improve my code style and writing. And like TheIdeasMan recently said, I also want to know "logic"... What is logic? And, how to make a perfect code logic....????
Last edited on
What would be an example of some code you write? we can't just read your mind and find out what code practices you have 'wrong'. Some common way of organizing code would be:

Functions
1
2
3
4
TypeName FunctionName(Param1, Param2, Param3)
{
    //.....
}


Declaration
1
2
3
4
TypeName Var1 = 0;
TypeName Var2 = "String";
TypeName Var3, Var4;
Var3 = Var4 = 0;


Classes
1
2
3
4
5
6
7
8
9
10
class ClassName
{
    private:
        TypeName Var1;
        TypeName Var2;
    public:
        ClassName();
        ~ClassName();
        TypeName FunctionName();
};


and so on, what part of code does your friend say is 'wrong'?
closed account (z05DSL3A)
I would suggest that you post some code snippets so others can reformat to discuss something more tangible...but generally whitespaces are your friend (and Verdana is not a good font for code)
This, please see my "Interpreter construction" and let me know what you think.
This is what I mean (and I am not JM's friend, unless things change a lot)...

http://www.cplusplus.com/forum/lounge/86638/4/#msg465782


..... and write down multiple group code in a line... I use the special code format, so I no need to worry about the code indentation. And, I always want my source to be short (as short as possible) by removing all tab characters and non-necessary space and enter characters, because it will make the sources IMO look easy,and I'll have more time to think up about new things...


And that is why it is hard to read.

So do these:

1 statement per line;
Proper indenting - closing braces in the same column as the opening statement, like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
     for (int a= 0; a <10; a++)  {
             if (condition)  {
                 //your code here
                   if (condition) {
                       //statements      
                   }
             }
             else if (condition) {
                    //statements
             }
             else {
                    //statements
             }
    }


Except there would be 4 spaces of indent - the code formatter does 8 on this page it seems. You can get your IDE to do this automatically.

See how easy it is to see what is what - not wondering where the end of a block is.

My other objections are the use of infinite loops where they are not warranted, and the use of goto.

There are situations where infinite loops is valid, but I object to the lazy use of them.

There have been long discussions about the use of goto in C++, the conclusion seems to be that they are very rarely needed - can mostly be handled with exceptions and try blocks. I especially object to the lazy use of them to achieve looping, or something that should be a function.

By program logic, I mean that a program should be easy to follow. In the post above there is a menu with 2 options. The code asking for which option appears at least twice. This would be much better handled with a ShowMenu function, and a switch that processes the option by calling a function for each case.

Then there is taking a C approach, when a C++ approach would be much easier. This is a C++ forum after all. Maybe you need to learn more actual C++. A C program with cout, cin, bool doesn't count as a C++ program really. I mean people write these programs and think they are doing C++. C++ written properly is actually quite different to C.

But the main annoyance is giving out code like that as advice to newbies who probably don't know any better. Like the advice given to this poor bloke here:

http://www.cplusplus.com/forum/general/84789/


goto Case; is a fine example.

To top it all off there is occasional criticism of senior experienced & knowledgeable members.

BTW, I am not claiming that I am an expert in C++ (on the contrary I have much more to learn), but I do recognise bad when I see it.

With your other program (the 432Kb one) you said it was a debug version, and required a 500Mb stack !!
I was asking what it actually did - suggesting it might display the menu, then run an existing application.

Your answer tells me 2 things:

432 Kb is actually rather small for an executable program IMO, if it is a debug version, then it will be full of extra info, leaving even less room for code that actually does something - implying that it doesn't do much at all.

If the program requires a 500Mb stack then there is major problems with the way it is written. So we have a program that doesn't do much and is very badly written.

Now you wonder why I am sceptical about the Child Language / interpreter / StarTrek Enterprise (as I call it) project. Today I pointed you to a link so you could learn what an enum is. And I asked if you could learn about if there are better ways of doing things than using #define.

Can you not see that this project is far far beyond your capability right now?

Sure, you might want to learn, but what we have had so far is lots of questions, replies by senior coders, and no clear idea from you as to what you are doing. This why I was trying to warn others about the fruitlessness of providing advice to you about this outrageously ambitious project of yours.

I hope you don't behave like this in your real life, if so, someone is going to trim you down to size one day, maybe it is better if it happens here rather than with real consequences elsewhere.

So, I think you should spend quite a bit of time in learning actual C++, by doing small programs (1 or 2 pages say) to test out various features of the language. Get some good books, do tutorials, read the reference material & articles on this site, study the advice given by senior members to others. Don't try to help others, instead post your own code and ask if could be improved.

In the past, I have accused you of being a troll, or at least of being a nuisance. Can you see now, from my point of view why I would have those thoughts? Now I am thinking you may be just really overly ambitious. Hopefully you will take this advice I have given you now, on board, and start learning and "Get with the Program".


Last edited on
I have just seen JM's code for the Child Language thread, and all my comments above still stand, although we were posting at the same time.

There are a bunch of other errors / bad practice that I am sure can be sorted out. I am going to have an early night - in bed before 1 am - wohoo! I will see what greets me in the morning.
Last edited on
Ok and conclusion :
I will continue building the interpreter..... (+_+) -> that
And hope all is going well for me at my end.......... (º.º)\
I'll be back!!!
Expect me, TheIdeasMan and... everybody!!!!!!!!!.. ^.^ ^o^ ^.^
Last edited on
closed account (z05DSL3A)
Don't take this the wrong way but I have now had a look at some of your code and it is a mess, TheIdeasMan does seem to raise some valid concerns. I would suggest that you take a look online for C++ coding standards and or style.
Topic archived. No new replies allowed.