Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Quick background: I'm in an advanced C++ course for a study abroad program. The problem is that I don't have any background in C++. I have a modest C background, but I'm starting to think I have more holes in my knowledge than I knew about.

My problem is that I'm writing really shitty code right now, but the university has an automated testing system that always seems to stump me in some way: does your code meet all the automated tests (no points if not), did you use the naive solution in terms of time or space (you get less points for this), do you have ANY memory errors (usually no points if so).

So, my question is what do you do during development that leads to verifiable, integrated results? Is there a better way to learn and develop so I'm not always cornering myself with features of C/C++? I'm looking to develop a method of software engineering for myself in which I can get full points for these homeworks in less than 10 hours per week (I'm currently spending 15 hours and not getting full points).

share|improve this question

marked as duplicate by gnat, MichaelT, Dan Pichelman, GlenH7, ratchet freak Apr 22 '14 at 14:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Do you run your own static analysis programs? or memory checks on your homework before handing it in? – MichaelT Apr 20 '14 at 22:32
I'm not sure how in depth you're talking for the static analysis (or if I'm off-base here), but I run many assert() statements with the simple test cases which are always given in homework specifications. Also, once the program seems to meet all the simple assert tests, I run it in Valgrind to detect any memory leaks, invalid read/write business, etc. – ironicaldiction Apr 20 '14 at 22:38
Things such as these. And this Stack Overflow question. – MichaelT Apr 20 '14 at 22:48
What exactly is "naive"? What makes good code doesn't change from language to language. You not having memory errors is pretty basic. You are being told the reason your not getting full points, so you know what your doing wrong, I am not sure what the problem is. – Ramhound Apr 21 '14 at 12:27
I'm surprised that you can't use those error checks without submitting. Is that non a possibility? – TruthOf42 Apr 21 '14 at 12:29

3 Answers 3

Code review is vital. In the professional world, you're almost always learning a "new language" on the fly, in that the existing code base represents an ad hoc domain-specific language that may run to millions of lines of code. In this environment, code review is always important—your colleagues often have knowledge of a different subset of the "language" than you do, so reviewing your code helps them and you.

In the context of a classroom setting, this is a little awkward; but I'd ask whether you have any friends who are also taking the class. If you do, you can share the burden of reading each others' code for errors. You will learn things from them, and vice versa. Failing that, there's always the Code Review site, and there are other online forums where people are relatively willing to read and comment on your code. Language-specific subreddits, for example, can be surprisingly useful; you might try cpp_questions. (Disclaimer: I do not write C++ and make no claims to the quality of this particular subreddit.)

In addition, you should make sure to read a style guide for your particular language. Google's C++ Style Guide is pretty extensive, for example.

share|improve this answer
I always wondered how professionals deal with the burden of being in a (rapidly) evolving domain of knowledge like programming. Interesting thoughts on code review with peers and on the web. – ironicaldiction Apr 20 '14 at 22:45
If you're thinking about having a fellow student review your code, make sure you do it in a way that is not considered cheating by your professor. If you're not sure what would constitute cheating for that class, ask the professor. – Michael Shaw Apr 20 '14 at 23:05
This was a decent answer until you brought up Google C++ Style Guide. – Cubbi Apr 21 '14 at 5:23
Fair enough; I don't write C++, as noted in the question, so if Google's style guide is regarded as poor, what's a good alternative? – syrion Apr 21 '14 at 11:27
@syrion - There is nothing wrong with it. – Ramhound Apr 21 '14 at 12:29
  • does your code meet all the automated tests?
  • did you use the naive solution in terms of time or space?
  • do you have ANY memory errors

Those are all software requirements.

The way you achieve a good score on your class assignments is to make sure your software meets those requirements. If you don't know exactly what those are, ask.

Learning a programming language is mostly about learning the syntax of the language (how things are spelled, where to put the brackets, etc.) The underlying fundamental principles (loops, functions, etc.) are the same from language to language. Learn the fundamentals well, and learning the languages will become easier.

share|improve this answer
I like the simplicity of your answer; it provides a useful metric by which I can judge my learning. Perhaps one should also pay attention to his style in the new language as well, or is this distracting from the main goals you've mentioned? – ironicaldiction Apr 21 '14 at 16:18
"Good Style" is a bit vague for a software requirement. If one of the software requirements is that the assignment should use "Allman-Style Braces," now you have a requirement that is specific enough to be addressed. – Robert Harvey Apr 21 '14 at 16:34
Okay, so let's formalize this; maybe I'm being too anal about the dev cycle, but I think a framework helps: (1) Read the problem and learn it well (2) Break the problem down into the first codeable chunk (3) Code it the naive way (4) Are there memory leaks? (5) if 4, fix (6) Are all the automated tests met? If no, repeat 1-5 (7) Is it worth time to solve the problem better? if yes, repeat 1-6 replacing (8) Have a beer. naive in 3 with elegant. Could anything be better in this "problem solving algorithm"? I think I'll try this approach on the next problems. – ironicaldiction Apr 21 '14 at 16:48
@ironicaldiction: You're not being tested on your dev cycle, just the result. You can use whatever dev cycle you like, so long as it helps you meet the requirements of the grader. – Robert Harvey Apr 21 '14 at 19:12

Divide and conquer. First solve and code a solution to the problem in a programming language or environment that you know really well. Then after you've debugged solving the problem, work out how to (re)solve the problem in the new language, improving the solution if possible by using the newer or different features of the new language.

share|improve this answer
If I had more time for the assignments, I might actually do this, since I already know Java pretty well. I think it would be more of a time hindrance for me at this point, though. – ironicaldiction Apr 21 '14 at 19:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.