Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm getting into the more advanced programming classes at my university, and feel like I am running into some obvious shortcomings with producing quality code.

For example, my data structures class has us reading in a list of songs, creating Song objects, then using various structures to implement searches for artists, titles, lyric words and lyric phrases. The professor gives us a list of test examples to prove the code produces the expected results, and the grades are based on functionality, completeness, and bug awareness. Currently I am holding a 90 average in that class, but am not really satisfied that my code is of good quality.

So, what techniques did your college professors use to get you to write better code?

share|improve this question
5  
The apprentice said to his master, "my paintings are no good they need work" the master said "practice my good apprentice, practice" The apprentice practiced and sure enough he learned to produce great art. The same goes for code, practice makes perfect. Experience trumps knowledge in this situation. –  Chris Nov 17 '10 at 15:47
3  
Relax, CS professors are often one of the worst programmers. Learn about unit tests. –  Job Nov 17 '10 at 16:08
    
Having your code pass unit testing is a prerequisite for getting a project graded in data structures. That and learning the eclipse debugger has saved me alot of frustration –  Jason Nov 17 '10 at 16:17

8 Answers 8

up vote 19 down vote accepted

Can I be honest and say they did nothing at all?

University courses tend not to be in enough depth to get into that sort of thing. They're more concerned with making sure you've learned how to do something and don't have the time to move on to doing it well.

Just to be clear, I'm not knocking university lecturers, or saying that they don't know what makes good code. Just in 10 - 15 weeks of lectures, a few hours a week, with minimal one on one time it's unlikely to happen.

share|improve this answer
    
So true... Once in a while you might get a good teacher who will go into more detail if you display an interest in it, however most just wanted their students to pass the class. –  Rachel Nov 17 '10 at 15:46
3  
+1. One of my professors once said, "We can only show you the beginning of a subject - you have to work on your own for the rest". –  MAK Nov 17 '10 at 20:21
    
As a professional getting a graduate degree while working, I realized early on that my professors' code (every single one of them) would not have gotten a good response at code reviews at my company. –  justkt Nov 18 '10 at 15:58

In my core CS courses (data structures, oo, etc) I had the same professor. He would take off major points if your program didn't do what he assigned, and minor(very, like 1/2-1/4) points for not doing it in the best/most readable/most efficient way. He then would write the 'correct' way next to the area on the hardcopy printout of the program. After he completed grading an assignment, he would spend part of a class period going over some of the most common errors and not-best code, and also explain how to fix them.

This professor also had a style syllabus he gave us all at the beginning of the sophmore year. Code for his class had to be formatted in his style. Minor infractions were worth minor points, as well. That taught me the importance of being consistent in my formatting. Also, several of my classmates have said that learning early to program to a standard helped them when they got jobs that had strict coding standards.

share|improve this answer
2  
+1 to your professor, wish I had someone like that when I was in school –  Rachel Nov 17 '10 at 15:47
    
the dept has style guidelines, but that is pretty much it. Wish I had your prof! –  Jason Nov 17 '10 at 15:54
2  
I wish everyone had such a prof :) –  aufather Nov 18 '10 at 11:16

Some good rules of thumb for producing good code.

  • Write documentation before code
  • Write (or at least), formulate test cases prior to implementation of code.
  • Professor told us: "There is a large gap between industry and academia. Learn to embrace this when you jump into your first career."

These will take you very fair during your programming career. We are not always perfect at it, but if you give some effort up front to these you will see a better resulting code.

Documentation prior to code helps gather thoughts, in the same way defining specifications helps define the problem. Testing prior to coding will also help you refine your functions/methods and give more direction to your code.

The 3rd piece of advice is the best, you need to realize you are when you graduate not a great programmer. At this point you are a programmer who has had a taste of programming in all sorts of langauges/situations. You are a programmer who knows how to learn how to program. This is all you need, you take your career where you go from there.

share|improve this answer
1  
+1 for the note that there's a large gap between industry and career. As someone who's taking classes right now, it's something I try to stress to my class mates repeatedly. –  EricBoersma Nov 17 '10 at 16:14
    
@EricBoersma: Sometime it is hard to grasp until you see it for yourself. Great advice though is best served this way though. –  Chris Nov 17 '10 at 16:15

just another cherry on the cake -

University courses are intended to make you capable of understanding what you desire to. They actually make you a 'beginner' so that you can learn what you want as starting from scratch is very difficult..they kick start your learner's mind.

share|improve this answer

I learned the most being a teaching assistant and grading others code than I ever did in lecture. The code I graded followed a classic bell curve, most was exactly the same, a very small portion was horrible, and a very small portion was incredible. I learned the most from grading the horrible and incredible. The incredible for obvious reasons. The horrible because I had to try and find where they went wrong and give pointers without just coding it for them.

share|improve this answer

I can't say the programming courses at uni taught me any certain techniques to improve my code -- I had to figure that out on my own.

However, they did subject me to a valuable experience: having to program in pairs or groups. This forced everyone to think about communication and how to write the code in such a way which could be understood by someone else than yourself. It doesn't matter how good a programmer you are if you can't get the others to understand what the hell you're doing. Imagine trying that in industry...

share|improve this answer

The truth is CS professors won't help you write good code AT ALL. Their job is to make sure you learn a certain language, and thats that. Countless number of times, I've been approaching the deadline for an assignment and ended up throwing together a mash-up of some terrible code and got an A+ for the assignment.

If you want to learn to write good code, the single best thing you can do, IMO, is take up an internship at a company/corporate and write code for them. Its surprising how the quality of your work goes up when there is no room for poor quality code.

share|improve this answer
    
I would add that professors' jobs are to teach you data structures/algorithms/theory even more than languages, but other than that - yes. –  justkt Nov 18 '10 at 15:59
1  
yes, that is correct. Coming to think of it, apart from C++ in high school and freshman year, I've picked up all other languages on my own. But its amazing how much an internship can teach you. In a 6month internship you can learn more than in an year at college. –  xbonez Nov 18 '10 at 16:48

Well, in our C++ class the professor would sometimes come and stand behind us and point at a "new" statement. We then had to show him the "delete" statement. You'll learn it in no time...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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