5 ms·
IMHO, the thing that new programmers really struggle with is learning how to break a problem down into the steps their language allows them to express. Lots of
by bane 13y ago
IMHO, the thing that new programmers really struggle with is learning how to break a problem down into the steps their language allows them to express. Lots of people have never had to logically think out and algorithm to do simple things and it takes them lots of practice to understand how to do that.
For example, suppose I'm a new programmer given the notional task of making a program to make me a sandwich, can I just:
makeSandwich();
and be done with it?
Or do I need to break it down to the n-th degree?
//make bread
bread=harvestwheat();
bread=millwheat();
bread=bread+water;
//and so on
is that the right way to even make bread? Or do I already have bread I can work with someplace?
Do I?
Sandwich=bread+jam+butter+bread;
Or
Sandwich=Sandwich.add(bread).add(jam).add(butter).add(bread);
Or do I need to do something else? Maybe this particular programming environment doesn't need me to make bread, but I have to transform a milk object into butter for some reason that seems entirely random to the new programmer. Who knows? Lots of the things that we take for granted seem entirely arbitrary to the new programmer and learning to break a problem down in a way that maps to the environment is a very hard problem to learn to solve repeatedly.
edit in a way this is a common topic even on HN with the "do x in n number of line" posts that are common.
- spion 13y agoHere is a methodology that I recently started using: Describe, at high level, what needs to be done to make a sandwitch, in your head. Then write code that looks exactly like what you said in your head, as much as possible. Dont worry if it turns out to be impossible to implement that way - you can always tweak it later until it becomes possible. Just try to make sure it reads more or less clearly. Repeat with each of the steps, checking whether there already is a library that does that for you. function makeSandwich() { var breadSlices = getBreadSlices(2); var ham = getHam(); var butter = getButter(); var butteredSlice = spread(breadSlices.first(), butter); return foodPile(butteredSlice, ham, cheese, breadSlices.last()); } Continue the same way with getBreadSlices, getHam, getButter, pile. As you progress this way, you'll notice that you'll be able to implement some processes in terms of more generic functions (e.g. spread and foodPile). You'll also notice that you need an environment (macro, such as kitchen, or micro, such as frying pan) to temporarily place stuff that you're working with, while you wait for some process to complete. Thats when you start creating classes and objects that represent this environment. Real code example: https://github.com/jlipps/async-showcase/tree/master/promises-bluebird-topdown https://github.com/jlipps/async-showcase/tree/master/promise...
- anuragramdasan 13y agoGerald Sussman had explained this in one of his SICP classes. He called it wishful thinking. One of the best ways I ever came across to break down a problem.
- tseabrooks 13y agoI know it's a bit silly but the thing that jumped out about your comment and the parent comment is the butter. You butter a hame and cheese sandwich? Is this a cultural thing I'm not familiar with? zooms off to google to check
- oneeyedpigeon 13y agoI can't think of a sandwich I wouldn't butter, including peanut butter.
- epochwolf 13y agoMy dad does this. I don't get it.
- zwieback 13y agoIn Germany it's common but regionally different. My Swabian friends thought it weird I'd do that but my family is from the North. After 25 years in the US I now think it's gross.
- mattmanser 13y agoUK, every sandwich buttered. Helps hold things in place.
- tseabrooks 13y agoAh, here we'd only butter a sandwich if it were being fried (Grilled cheese or grilled ham & cheese)
- twic 13y agoJust to be clear: are you thinking of buttering the inside or the outside of a sandwich? In the UK, standard practice is to butter sandwiches on the inside, ie on the surfaces of the bread which interfaces with the filling. Are you by any chance talking about buttering the outside?
- twobits 13y agoTotally agree. A simple example: print, princ, echo, cout, ... For god's shake =8-/