my C++ pirate game [judge]

Pages: 12
closed account (3bfGNwbp)
http://pastebin.com/LYKD3Aj7

i think I did but but I need someone to judge it before I sell it on hackforums.
my friend says i should adopt his coding style, but i dont think i need to. I mean no offense, but his code looks horrible.
Last edited on
You might want to look into functions and loops so you can get rid of those gotos.
Edit: Do you really plan on trying to sell this?
Last edited on
closed account (3bfGNwbp)
not for much, just like .50c to play around with. and I'll look into that, but wouldn't it make my code longer?
Possibly, does that matter? Functions and loops make code much more readable.
closed account (3bfGNwbp)
yeah but optimization is better than readability
I completely disagree, but I guess its a matter of opinion. Any speed gained from goto over a function call likely would be miniscule.
closed account (3bfGNwbp)
i guess, but it looks better, to me. and my friend says I should adopt his coding style, but it doesnt look as good as mine.
Last edited on
You don't know the issues involved with the labels when it comes time to debugging. Your program technically doesn't flow from the top down like C++ was designed to. In a typical C++ program, you start at main() { and read down until you reach } but in yours, you're bouncing all over the place. There is also no purpose to putting SRO for labels since it's all going to be getting used as well. You were also talking about optimizing your code, yet you use strings for user input of integers, you use complicated functions in your if statements when you're comparing, when you could have just used a switch.

I'm not trying to destroy you or your code, just simply point out the improvements you asked for. There is a reason why everyone suggests you using functions, and it's not just because we think it's right. Plenty of people here, myself included, have had their share of headaches with programming. I've dealt with labels before and I swore to never use them because of what I had to go through.

You also create a lot of variables at the beginning of your code, causing your program to use a large, relative to the simplistic nature of the program, chunk of memory for variables you don't use, or may never use. So I don't feel that your code optimizes much of anything. And doesn't improve over anything when it comes to readability sacrifices.
closed account (3bfGNwbp)
so my friend was right about my code? I'm using the style of coding they did back in the 80s with goto?
then why do the have goto if it's bad? What makes his coing better than mine? His looks bad to me.
Last edited on
Do you realize how much technology has changed in 30+ years? Technology was limited back then, but even as far as I know, labels were considered bad back then, but they have their purposes. And since C++ is supposed to be backwards compatible with C, it's still in the language.

Also, I don't know what your friend's code looks like, but with C++, you can have two coders who have the same style and their programs look completely different. There is nothing wrong with limiting the number of lines your code has, I do it, but do it within a sense of coding. If you haven't learned functions yet, learn them. There is so many advantages of functions that labels don't offer.
closed account (3bfGNwbp)
http://pastebin.com/bpD1R8am

this is his project from a month ago. the reason we got into a fight was because he is learning about optimization in c++ and was complaining about how bad mine was. it pissed me off

whats a good function tutorial???
Last edited on
There is a lot of issues with his code, but this isn't the discussion for it. He seems like he is also much further in the language than you are. I also don't like his code much myself, but even the most elegant code is ugly to some people.

As for tutorials, this site has a great beginner tutorial. You can skip the parts you know, and read the parts you're unsure about, and really read the parts you don't know. The tutorial is located here: http://www.cplusplus.com/doc/tutorial/

There is a lot to learn, and learning a good "style" isn't easy either.
closed account (3bfGNwbp)
what's wrong with his code? I could use it as an argument against himZ or should I just make a new thread

And what do u mean by style?
Last edited on
The only thing I see is he doesn't seed the random number generator.
Edit: And he uses quite a few magic numbers.
Last edited on
This covers one part of "style":
http://en.wikipedia.org/wiki/Indent_style

I personally use the 1TBS, or 1 true brace style. But I also tend to break else scopes on a different line than the proceeding if SRO with a 3 space indentation. I use AStyle to keep my code formatted so I can easily read it.

There are other styles such as naming conventions and others.

Edit: Also, don't worry about using arguments against him, he'll more than likely rub your bad techniques in your face or your limited knowledge. I'd just focus on expanding your knowledge and finding a style that you like. C++ is a fairly unique language in that you can make your code look however you want.
Last edited on
closed account (3bfGNwbp)
seed? WTF? Lol. somebody in English?

Gotos are fine in the end but they lead to really terrible looking code that is a nightmare to manage in larger applications.

In the end every loop is converted in to a goto or more specifically a jump because that it how the CPU coding sets work. Loops just make things so much more pleasing to read and you should use them if you want to be taken seriously.

Modern day compilers will take care of the optimization as long as your code isn't redundant or poorly designed. If you are that worried about optimization than why not code in assembly where you can directly code with the CPU's instruction set? You won't be able to use it on different CPU's but who cares, it's optimized, right?
closed account (3bfGNwbp)
so there is no need to optimize any code? dude then why did my friend even bother telling me to fix my code?! im sure he could work around it.
@TheBestHacker
He may not have meant optimize it as in the sense of speed/efficiency, but rather optimizing it for better readability. You can always improve readability.

@IceThatJaw
Gotos are fine when needed, but with as much syntax that exists in C++ now, it's very rarely needed. And yes, loops are essentially a goto/label, but that doesn't mean that they should replace functions as TheBestHack's labels do. And most compilers will optimize redundancy and poor design. But they have their limits as well.
Pages: 12