code contest

Pages: 1... 56789
I'm trying to do some kind of weird console graphics library (not images, just two- and three-dimensional shapes and lines and stuff). I was somewhat inspired by what hamsterman did a while ago, as well as OpenGL (which I used a few days ago for the first time). I'm trying to give the API the same does-it-all feel of SFML while still having the DIY aspects of OpenGL, and the cleanness and ease-of-use of both libraries.

I doubt I'll be finished in 6 days, though, since, although I'm finding it easy so far (designing classes and writing function declarations), once I get to the 3D part I think I'll struggle. I can definitely do 2D shapes (I wrote a program once that drew circles on the screen, and detected when one or more of the three circles overlapped, I think that was last Summer or maybe the one before), so maybe I can post that if I can get the library to work without the third dimension.
Last edited on

The program reverses the order of the words in a sentence that the user enters. For example, if the user enters "I like C++", the program will output "C++ like I".


This is really awesome that you spent time writing a whole lot of C++ code to accomplish a trivial task which can be done better[1] with a single statement of <choose some more expressive language here>[2]. And that including the I/O.

[1] with no hardcoded word count limit
[2] however, it is still possible to make that much better even in C++, although not in a single statement


Last edited on
Albatross wrote:
Protip: Ignoranceing is bliss. ;)

http://www.cplusplus.com/forum/lounge/41016/6/#msg227733

ulfinitus wrote:
Protip2: No one cares whether one language is better than another.. Except those who's opinions won't be swayed.

http://www.cplusplus.com/forum/lounge/41016/6/#msg227782
Last edited on

No one cares whether one language is better than another..


Using appropriate tool for the job is essential part of software engineering. If you can't understand this, and you don't care which language / tool is better for the job, programming is probably not for you.

Anyway, if you can't understand my post was actually not about one language being better than another, but about writing ugly C++ code for an "awesome code" contest, programming is probably even more not for you.

If you happen to write 50 lines of code to accomplish something trivial, that someone could do in one line this means one of the following:
1. You are using wrong language.
2. Your code sucks.
3. You do it deliberately to achieve some other quality, e.g. better performance, lower memory usage, better genericity etc.

Guess, what was the case here?


Last edited on
Wow. Quit being so damn arrogant and putting people down. It's one thing hating on a language, but you're now flaming someone who is possibly new to C++ (and possibly new to programming in general) just because you can do the same thing in less code. Who gives a fuck? Usain Bolt can run faster than anyone else (as far as anyone knows), do you see him telling everyone else to give up? People that are new to something that you're already good at should be encouraged, not told that they're not worth shit because you're better. I was wrong, you should be banned.
Last edited on
When I was new to C++ I didn't show my code as "awesome". If someone does it, one should be prepared for critique. Not telling someone his code sucks is far worse than being a little too harsh - because many programmers tend to stay with the style of coding / tools that work for them although are very far from optimal.


People that are new to something that you're already good at should be encouraged, not told that they're not worth shit because you're better


Where have I said it?
Last edited on
rapidcoder wrote:
If someone does it, one should be prepared for critique. Not telling someone his code sucks is far worse than being a little too harsh

I'm not saying not to critique it, but what you said was not a critique. Something along the lines of "that could be improved in x, y and z way" would have been much more helpful and would not have received a negative reaction from me. You decided to use a decidedly unhelpful way, being all sarcastic:
rapidcoder wrote:
This is really awesome that you spent time writing a whole lot of C++ code to accomplish a trivial task which can be done better with a single statement

That's swell, but he chose to do it that way. You could have said "you could try and make it possible to have an arbitrary number of words, rather than just 100" and "you could do it in less lines than that" but instead you decided to be unnecessarily cruel.

rapidcoder wrote:
People that are new to something that you're already good at should be encouraged, not told that they're not worth shit because you're better


Where have I said it?

Ok, you didn't say it exactly like that, I overreacted. But still:
rapidcoder wrote:
writing ugly C++ code for an "awesome code" contest, programming is probably even more not for you.

This is too harsh.
Ok, I was too harsh and sarcastic. Sorry. I wouldn't react so if it wasn't "awesome" code contest.


writing ugly C++ code for an "awesome code" contest, programming is probably even more not for you.


But this was not to the one who has written the code, but who repeats everytime that programming languages are equal and noone really cares. And if we are talking on "awesome code", yeah code, than language and style actually matter the most.
baaaaannANNA!

Life's good mates. Move on. Write awesome code. ??????. Profit.
rapidcoder wrote:
Ok, I was too harsh and sarcastic. Sorry. I wouldn't react so if it wasn't "awesome" code contest.

Ok, that's fine; I'm sorry I reacted the way I did.

rapidcoder wrote:
But this was not to the one who has written the code, but who repeats everytime that programming languages are equal and noone really cares.

Albeit true that C++ isn't the best language for text processing, that is still something that it will have to do (the library I'm working on uses a timestamp() function to get the current time in a given format, for example; another example would be the *printf functions) and it is better to know how to do it in every language you learn than in just the ones that are best at it. Using Perl would probably be easier and take less code (I'm sure it could be done in one line with Perl) but it doesn't really matter.

rapidcoder wrote:
And if we are talking on "awesome code", yeah code, than language and style actually matter the most.

But given that this is a C++ forum, implicit in "awesome code" is that OP meant "awesome C++ code" (which the OP also said it had to be C++ here: http://cplusplus.com/forum/lounge/41016/#msg222899 ). I agree, though, style does matter.
rapidcoder, I never said that the code was awesome? As chrisname said, yes I am a beginner, but is that a good enoguh reason to denigrate me? You probably weren't so much better yourself when you were a beginner. Say for example that your son (if you had one) was proud because he had learned multiplication, would you tell him that he sucks just because you know division too? You wouldn't, and if you would, then you're probably mentally ill. I'm not sure if that example was very clear, but I see your behavior as directly rude, and you should think twice before posting something like that again.

I used 10 minutes to write that program, and I CAN write better programs, though I'm not going to post it here, because no matter what it is, you would probably just post a stupid comment saying how much better you could do it. This was just something I quickly made while I was bored.

rapidcoder wrote:
Using appropriate tool for the job is essential part of software engineering. If you can't understand this, and you don't care which language / tool is better for the job, programming is probably not for you.


I agree with this statement 100% - out in the industry, I have met so many experienced developers who can only see nails because they are holding a hammer in their hand. It's unfortunate and it's frustrating working with some of them, because there's better stuff coming out all the time.

For example, there is a growing consensus that the new generation of JVM languages, like Scala, will supersede Java because they are more elegant and more concise (fewer LOC) and can deal better with the advent of highly multithreaded CPUs.

This is a good thing, but it doesn't mean that older languages are totally obsolete.

In my case, I chose C++ for writing a multithreaded realtime server, for performance reasons - I wanted to be close to the metal (though, in the future, I may try using "D" or "go" to replace this version). For the client side, I chose Scala because I wanted to get a GUI up quickly and it was nice having the extensive Java API available on hand. I will also use scripting languages like R or Ruby, if they fit the task at hand.

In my experience, the interesting thing is, I have a hard time finding "beautiful C++" code in my repertoire - this could be because my C++ skills are insufficient or it could be that the language is not conducive to writing beautiful code or most likely, a combination of both. Sometimes, when a C++ design pattern fits like a glove, that's a beautiful design, but that seems to be somewhat removed from beautiful code.

FWIW, I have definitely seen some really beautiful Scala and Ruby code, though. Smalltalk also results in extremely readable code (in particular, Kent Beck, of Extreme Programming fame, is very good at writing extremely clear code).

IMHO, beautiful code is concise and semantically rich.
That means a high signal-to-noise ratio in the code.

You can glance at it and understand exactly what it's doing.

To me, that's "awesome code."
Last edited on
"If you happen to write 50 lines of code to accomplish something trivial, that someone could do in one line"

GUESS WHAT

1
2
3
#include <iostream>
#include <string>
using namespace std; int main() { string sentence; string words[100]; int wordcount = 0; cout << "Enter a sentence: "; getline(cin, sentence); int length = sentence.length(); for(int i=0; i < length; ++i) { if(sentence[i] == ' ') { ++wordcount; ++i; } if(wordcount >= 100) { cout << "\nERROR: Too many words.\n"; return 0; } words[wordcount] += sentence[i]; } cout << endl; for(int i=wordcount; i >= 0; --i) { cout << words[i] << " "; } cout << endl << endl; return 0; }


(Stupebrett's program)

But seriously, surely all this isn't very helpful in that nobody's going to want to post anything here while rapidcoder is rapidly scaring everyone away.
Last edited on
rapidcoder already apologised; why are you still having a go at him? And though that is one line (of actual code, 3 lines if you include the pre-processor), it is still more than one statement.
I think both my points were still valid.

And yeah, I'm aware he meant statements and not lines (he's probably too used to Python or something), but it was a joke (all I had to do was delete single-line comments and new-lines).

I'm of the belief you can still criticise people when they've apologised, and more so if they had reason to apologise.

I'm not trying to be too harsh on rapidcoder or anything.

I have to admit to being quite a bad programmer in rapidcoder's opinion because I don't see how being able to write one line of code to do something special means that a language that can't do it in one line isn't as good for awesome code. Especially since the most restricting languages are the ones used to write compilers and processors for the so-called 'awesome' languages.

I'd understand if it was as innocent as saying some languages are more worth of your time than others for making some kind of useful development, because programmers who have learnt many different programming languages should really know when using them are efficient and productive, and when they're just a big waste of time.

But the matter of the fact is C++ is actually a brilliant language for most tasks. Especially since if the code to do something like make a GUI is difficult, there's likely a really simple library you can use to put in all the hard work so you can deal with the functionality, and in a professional environment the extra time it takes to get used to a library is made up for the efficiency of a C++ program. C++ is very well organised and there's no denying it, if you only ever learnt C++ then most tasks would be well accomplished provided you were competent.

Obviously I'm not going to say C++ is best for everything, because it isn't, but it is probably the best overall right now. That doesn't mean it has to be your favourite, that's completely up to the programmer.

I reckon I could write that word-swap program in only a few lines of C++ that wouldn't be too obfuscated, and most of the C++ programmers here could probably do the same (provided they aren't too new). I'm also aware that there may be other programming languages that do it all in one line, and don't even need pre-processor directives and all that. I've got to say, however, that is a really bad judge of awesome code in my opinion. Does it really have to matter what language it's in? It still does the same thing (although taking advantage of the other language may do it in a marginally different way). It's just a feature that wasn't included with C++ (which I'm happy about because I prefer stream-lined) or it's a style of programming which C++ wasn't made for, in which case it still does the same thing (because the other styles all end up compiling to the same, or worse, machine code; they just require less thought to write, which doesn't really make a good programmer).

Please explain, rapidcoder, exactly why it is that languages that use less code to do the same thing in one instance of programming practice are better. They all use the same algorithms (and if they don't, then the fault lies with the programmer, not the language, since provided it's Turing-complete you can program it). This is of genuine interest to me as there are many programmers who share your opinion outside of C++.

And then please explain why you decided this would be appropriate for a C++ forum discussing awesome C++ code, because I can't figure it out.
Last edited on
Veltas, if you had worked out in industry and have had to debug other developer's overly verbose, obfuscated, spaghetti code that has dependencies going in all directions, then maybe you, too, can appreciate that less is, indeed, more.

Awesome code is awesome code, whether or not it's in C++.
Last edited on
@Veltas http://www.stanford.edu/class/cs242/readings/backus.pdf
Food for thought.

edit: Just noticed.. Why in the world was rapidcoder banned?
Last edited on
hamsterman, great CS article - thx for the post!
(written by the venerable John Backus, of BNF fame)
hamsterman wrote:
Why in the world was rapidcoder banned?

Oops :S
I reported him earlier, but when he apologised I thought that the admin would see it and not ban him... I just sent a message via the Contact Us form to ask for him to be unbanned.
lol, now I kinda feel guilty because I think the post that got rapidcoder reported was the one written in response to my (sarcastic) post -though I'm not the one who reported it.
And to OP, I apologise for not making any positive contribution to your thread, best of luck anyways with your contest. I promise not to hijack this thread anymore :D
Pages: 1... 56789