Tell me more ×
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 have new junior programmers (new graduates) who just joined my team, some of them do not know much about algorithms and design patterns. I am not sure which one should I teach them first?

share|improve this question
12  
What kind of university spits out graduate programmers without teaching them about algorithms? – Dominic Gurto Jun 15 '11 at 6:04
2  
I'd recommend learning what they are first. – nbt Jun 15 '11 at 6:54
1  
@Dominic - "learning about algorithms" isn't really clearly defined. Which algorithms? Just the classics, or including things like cache-oblivious? Cookbook or deep understanding? How much on adapting the basic building blocks (e.g. augmenting data structures)? Priorities vary and, with fallible student memories too, it's amazing how often you'll find someone who seems competent right up until he says "what is this binary heap of which you speak?". – Steve314 Jun 15 '11 at 7:16
13  
The so called "design patterns" are only useful when you've got enough experience to re-invent them on your own. Before that, an epic abuse is inevitable, so it is better to stay away from that patterns quite for a while. – SK-logic Jun 15 '11 at 9:34
3  
@SK-logic - I disagree. Although without a context of how to design software, patterns aren't that useful. A software design course that teaches how to identify and use patterns is a second year course at the university I attended. – Thomas Owens Jun 15 '11 at 11:58
show 5 more comments

migrated from stackoverflow.com Jun 15 '11 at 6:52

12 Answers

up vote 24 down vote accepted

My vote goes for Algorithms.

Because algorithm is the main logic of a functionality once you know the algorithm you can easily apply that logic in any design pattern. Main logic is independent from design pattern.

share|improve this answer
off course to easily apply logic in any design pattern you have to know how the pattern works as well – stijn Jun 15 '11 at 7:04
@stjin: yeah sure. but it will become easy cause different design patterns only changes the place where we write logic not the logic for functionality. – Harry Joy Jun 15 '11 at 7:07
Not really. I'd go for design patterns first. In a well designed application, the algorithms can be exchanged seamlessly. So if they learn Design Patterns first, they can train algorithms easier. – Falcon Jun 15 '11 at 7:13
@Falcon while you do have a point, imo a thorough understanding of patterns (including the ability to spot which one should be used where, if any) is much harder than getting to know algorithms. Which is why I'd either recommend learning them first, or at least together with design patterns. – stijn Jun 15 '11 at 8:43

Let me be the odd one out and say design patterns.

They should have SOME programming knowledge I'd say, and specific algorithms can be taught when they are needed, or discussed with seniors.

Knowing some design patters (especially the ones you are using in your team!) would stop them from making expensive mistakes that a lot of beginners would (for instance: a lot of procedural code, messing up your MVC-patter, etc etc).

Explain them some basic logic about patterns, what you use and the specifics of the most used patterns. Then see if there are any algorithms that come to mind. Don't go mindlessly teaching them how to make binary trees.

There is ofcourse a difference in situations, but I'm assuming a junior is not in the position to do the very most crucial things. In the beginning any algorithm work might need brushing up, but they can pick it up as they go along. An algorithm can be 'bad' but fixing that and in the process teaching what you should've done is possible.

On the other hand, if you work in an environment where strict patterns are used a novice can -even when adding a simple feature, or cleaning something up- seriously damage the structure by adding stuff in the wrong place and messing up the concept of one of your used patterns. This would not only mean a rewrite of his/hers work, but also trouble for other programmers as their work gets harder.

I do wonder what they did actually learn from their graduation?

I want to add that if you dislike patterns etc, especially in the case of novices overdoing them, you definately need to teach them correct use (aka: when not to use or how not to use) patterns first. Before you know it you have half a pattern-design book implemented while you didn't want it. You still need to teach them patterns first (not "this is pattern A, this is pattern B" maybe, but the subject is still patterns) before you go starting to mindlessly teach them algorithms.

share|improve this answer
"strict patterns" - is this your own invention? Certainly not a term I've ever come across. – nbt Jun 15 '11 at 15:59
No, I was trying to say something about how stricly you 'enforce' a certain pattern. As opposed to shifting concerns that should be in class 'A' according to the pattern to another class etc. I didn't mean to imply this as a term, just as a description of how a software team might (or might not) work – Nanne Jun 15 '11 at 18:41

Depends upon what you are trying to do, and what tools you are using to do it.

For instance, for a basic web application using a high-level language like Java and a prebuilt web-framework like Spring, then in-depth knowledge about algorithms is not generally required (want to sort something efficiently, just call Collections.sort(), etc.), but knowledge about MVC design patterns is likely important.

But if you're building a multimedia processing application in C then algorithms may be at least as important as design patterns.

share|improve this answer

More basic than either. Coding style.

I would start them off with Code Complete and go from there.

share|improve this answer

It really depends on the nature of the work they'll do.

If it was a general question I'd say Algorithms, though.

share|improve this answer

Design patterns

Any time! Design patterns are fundamental in not only how we structure our programs but they affect the ways we actually think and discuss solutions. The earlier someone can get started with design patterns they faster they can become "fluent"

Algorithms are nice but let's face it, you can do ha helluva lot programming without ever having to implement an algorithm from scratch yourself. Knowing what algorithms are available and what they're appropriate for is a good first step for a junior programmer but I'd still say design patterns are far more important for daily work.

Algorithms tend to have far more programming "cred" then design patterns. Designing and learning sophisticated algorithms is the "cool" thing to do. In some areas you do need design and implement sophisticated algorithms but they're fewer then you think.

<rant>

I have a pet theory that algorithms vs design patterns is right-brain thinking vs left-brain thinking. Many programmers come mainly from the left-brain side of things with a deep interests in maths, science and engineering, it's very natural that they'd find algorithms more exciting. Heavy left-brain thinkers are typically stronger at a method level then overall architecture.

On the other hand we have the right-brain thinkers with a stronger aptitude for language, arts, and patterns. They might not be as strong on the method (algorithm) level but they're strong when it comes to overall architecture.

If you're going to be a good general programmer it's important that you master both left and right brain thinking

</rant>

share|improve this answer
4  
Since when this "design patterns" buzzwordy BS became "fundamental"?!? And, by the way, "design patterns" is the worst way of thinking on an architectural level, ever. Even worse than OOD. – SK-logic Jun 15 '11 at 9:38

Algorithms

My personal opinion is that you should not dive into design patterns before accumulating some experience with programming in general first. To get design patters you need to have a first-hand experience of the problems they will help you solve (someone who has never needed a fire will find it hard to understand the usefulness of matches).

Algorithm (i.e., how to think in code) training is a good way to train in problem solving, and you need to have that experience in order to harness the power of design patterns.

share|improve this answer

They're two separate things. Algorithms are low-level theory, design patterns are high-level practices. They don't intersect much.

share|improve this answer
Could be true, but does it matter? Mr or Mrs Anonymous asks what should be the first of the two, that's a valid question for intersecting and non-intersecting subjects? – Nanne Jun 15 '11 at 6:01
It'd really depend on what the programmers would be doing -- I can't make any general statements. aroth's examples work nicely as cases in point. – duskwuff Jun 15 '11 at 6:02
I agree, but I still don't see why it matters, only if you mean to say: "you should do both at once" or "Can't tell because they are so different". But I'm just confused why your general statement about the intersection of the two.... – Nanne Jun 15 '11 at 6:07
If they don't intersect, maybe play a design patterns video to the left eye, and an algorithms video to the right eye... – Steve314 Jun 15 '11 at 7:23

First, common problems.

Second, common solutions to these problems.

share|improve this answer

If your junior programmers know their language: definitely design patterns (and even before that: coding style rules ;) ).

From my very personal view: For 95% of all problems we can find excellent and performant algorithms (sorting, selecting, hashing, ...), so it's more productive to know when to use them (and which variant) then trying to reimplement the wheel.

Make them understand the basic patterns and why to use patterns. You'll have to tell them that class xy shall get notifications of state changes on class yz and they have to know, that you want them to implement an Observer Pattern and they'll have to be able to do it without further guidance.

If you have a very special algorithm, then you usually have some senior software engineer or an architect that will design the algorithm and hand it over for implementation.

share|improve this answer
One have to study algorithms in order to be able to design algorithms, to think algorithmically and to design an architecture of higer levels of abstraction. Not just for being able to re-implement quick sort over and over again. And patterns... Patterns are just a crap, nothing more. One capable of thinking on a decently abstract level won't ever need a collection of pre-cooked patterns. – SK-logic Jun 15 '11 at 9:41
@SK-logic - most likely the new team members will not design algorithms in their new (first) job. Once you start looking into complex applications (with more then one or two classes) and want to get things done, you need patterns. I'd never accept or even pay a developer in my team who refuses to use patterns just because he thinks he doesn't need them because he smarter then the rest of us. Never. – Andreas_D Jun 15 '11 at 11:46
as I said - learning how to design and analyse algorithms is a pre-requisite for learning how to design an architecture. Even if you won't ever implement a single algorithm in your life, you have to know how to do it in order to be able to reason about entities of a higer level of abstraction. There is no way around it. And, yes, you do not need that stupid GoF patterns for doing complex things. You need an ability to identify and invent patterns. Knowing specific patterns but lacking this ability most certainly will lead to a disaster. Just as well as any misuse of an OOD. – SK-logic Jun 15 '11 at 12:24

The most important is to start building a team. Develop coding style that vocabulary that makes you understand each other. Then move to programming principles that will make your code maintainable (simple and clear). When you reach that point you will know their potential and you will be able to guide them according to their skills. They should know both algorithms and design patterns with emphasis to the one that they will need more. Large scale design requires patterns while specific problem solving requires algorithms. Whatever you do I insist in the creation of a real team. It is the method I use and it never failed yet.

share|improve this answer

I know this is a cop out, but ....

It Depends

If your company is producing custom line-of-business software, CMS/Website development, and related things, Design Patterns will be the most useful. I rarely have to implement anything close to the algorithms learned in school in my work life (but its good to know them, plus learning to implement them is extremely valuable in helping you break down everyday problems). Yes, teaching a junior programmer Design Patterns will most likely casue them to start overusing them, but if you are reviewing their code on a regular basis (you should be) then hopefully you'll be able to nip the worst problems in the bud before they become a real issue in your code base. Plus, the Design Patterns flow well into helping them write testable code and the SOLID principles that are foundational to maintainable code, which is what is really important.

Now, if you are implementing Financial Trading code, scientific code, logisitics routing code, Algorithms are probably more useful, as these fields are much more dependent on the basic Computer Science knowledge to be productive, unlike business code which feeds off more of the Software Engineering side of profession.

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.