Teaching patterns

Arseni Mourzenko
Founder and lead developer
April 3, 2015
Tags: productivity 33 rant 33 thoughts 6

Col­lege de­grees in IT-re­lat­ed dis­ci­plines are known for not teach­ing some cru­cial things that every de­vel­op­er should know. Many stu­dents may be proud of con­tribut­ing to dozens of pro­jects, but don't know what a ver­sion con­trol is. They might spend months learn­ing de­sign pat­terns, but nev­er heard of mi­croser­vices. They may learn by heart the bi­ogra­phies of Bjarne Strous­trup and Don­ald Knuth, but have no idea who Mar­tin Fowler or Steve Mc­Connell are.

I'm OK with that. Three to five years is a pe­ri­od too short to teach the 600-hun­dred pages Code com­plete or a slight­ly short­er Sam New­man's Build­ing Mi­croser­vices, and it's not that hard to teach some­one how to use ver­sion con­trol.

What sur­pris­es me more is that no­body teach­es stu­dents nei­ther how to think like a de­vel­op­er, in oth­er words how to think about prob­lems, nor what pat­terns should one ap­ply in or­der to solve a prob­lem.

What is even more sur­pris­ing is that I re­call my years in law school when lec­tur­ers were telling us that the goal of spend­ing five years in a law school is to think like a lawyer. And in­deed, a few years lat­er, we were think­ing like lawyers. I also re­call the two years learn­ing psy­chol­o­gy, where we were trained to ap­ply spe­cif­ic pat­terns to spe­cif­ic sit­u­a­tions. For ex­am­ple, we knew that there are spe­cif­ic rules to ap­ply when de­sign­ing and con­duct­ing an ex­per­i­ment—a strict ap­proach to fol­low in or­der for the ex­per­i­ment to be con­sid­ered trust­wor­thy by our peers.

We had to learn by heart the names and dates of im­por­tant court or­ders, and we had to learn what Freud brought to neu­rol­o­gy, but those learn-by-heart things were sec­ondary; what was much more im­por­tant is those tran­scen­dent mod­els and pat­terns.

It looks like IT-re­lat­ed col­leges have cho­sen an­oth­er func­tion­ing. There are stu­dents who know ex­treme­ly well a spe­cif­ic pro­gram­ming lan­guage, or can re­cite the most used 50 de­sign pat­terns, but they sim­ply don't think like de­vel­op­ers, and they don't re­al­ly know how to solve prob­lems.

Is it a ques­tion of prac­tice? I don't know. My sus­pi­cion is that if not learnt in col­lege, this sort of things will be too dif­fi­cult to ac­quire lat­er.

Case study: a BSOD on boot

A ba­sic ex­am­ple. A new in­tern was spend­ing the whole day on a prob­lem: a vir­tu­al ma­chine starts to boot, then BSODs and re­boots. The in­tern re­mained pret­ty pas­sive, telling to oth­ers that her VM is not boot­ing, but not specif­i­cal­ly ask­ing for help, and, I imag­ine, not re­al­ly know­ing what to do to solve the prob­lem.

What would be your ac­tions if you were this in­tern?

It is not even a ques­tion of be­ing proac­tive. It's as sim­ple as ap­ply­ing a pat­tern to solve the case:

  1. Go see Win­dows Events. It prac­ti­cal­ly nev­er helps (be­cause most soft­ware doesn't log any­thing), but it's still a good start.

  2. Check Google. This one works near­ly every time. If you have a prob­lem which can be solved, there are chances some­one al­ready had this prob­lem, found the so­lu­tion, and pub­lished it.

  3. Try Last known good con­fig­u­ra­tion op­tion.

  4. Start the VM in safe mode to check the disk and sys­tem files.

  5. Ask for help (start­ing by col­leagues and end­ing by Stack Ex­change).

When try­ing those steps, the prob­lem was solved with­in min­utes: the ma­chine suc­cess­ful­ly start­ed in safe mode, and then restart­ed with­out BSOD.

Case study: du­pli­cate en­try in web.con­fig

Yes­ter­day, a col­league com­plains that an ASP.NET ap­pli­ca­tion is not work­ing and re­port­ing a er­ror about a du­pli­cate en­try in web.con­fig in a re­la­tion to En­ti­ty Frame­work.

I im­me­di­ate­ly ask if there are hi­er­ar­chi­cal con­fig­u­ra­tion files. No—re­sponds the de­vel­op­er. Giv­en that the ques­tion makes no sense (there is nec­es­sar­i­ly a hi­er­ar­chy there), let's as­sume the an­swer is ir­rel­e­vant.

OK, we are fac­ing a prob­lem. What could be the pat­tern? Since we have a er­ror mes­sage, the first step of the pat­tern may be to ac­tu­al­ly read the mes­sage—a task which most de­vel­op­ers pre­fer to avoid, be­cause er­ror mes­sages look scary. With­out ac­tu­al ac­cess to the ma­chine, I could only guess that the er­ror is about En­ti­ty Frame­work and a du­pli­cate en­try, giv­en that the ref­er­ence to EF may be ir­rel­e­vant. Let's search for “web.con­fig du­pli­cate en­try en­ti­ty frame­work”.

The first re­sult doesn't look promis­ing. It will prob­a­bly solve the prob­lem, but doesn't ex­plain why the prob­lem ex­ists in the first place.

The sec­ond re­sult is much more in­ter­est­ing:

The prob­lem was re­lat­ed to the root di­rec­to­ry of the site; I for­got it was point­ing to an­oth­er re­lat­ed pro­ject, with this pro­ject mapped to a vir­tu­al di­rec­to­ry. This lead to the oth­er web.con­fig be­ing loaded.

Is it a virtual site?…
It is.
Then you may want to check the web.config of the root site.
I didn't thought about that. I'll check it.

The fun­ny thing is that it takes sec­onds to find the an­swer. Pat­terns make our work sim­ple.

Case study: script­ing lan­guages and shell

The pre­vi­ous ar­ti­cle Script­ing lan­guages, au­toma­tion and pro­duc­tiv­i­ty was all about pat­terns as well.

The prob­lem is sim­ple. We have Ex­cel data we must ex­tract in a spe­cif­ic for­mat. The so­lu­tion might not be sim­ple, but the pat­tern to use to find the so­lu­tion is:

  1. Split the prob­lem. It looks like an ETL, so split­ting it like one makes sense. Ex­tract looks sim­ple: just ex­port the data in CSV for­mat. Load is re­duced to any­thing which can be copy-past­ed, such as a text file or ter­mi­nal out­put. Re­mains the trans­form: how could we do that?

  2. Think about the tools which can be used. In my case, I im­me­di­ate­ly thought about my own code. It solves the pri­ma­ry prob­lem: cal­cu­late the size of the columns and in­sert the white­space to align the sep­a­ra­tors.

    The us­age of this li­brary cre­ates an­oth­er prob­lem: the bor­ders of the cells and the table are not what we ex­pect. The so­lu­tion looks straight­for­ward: grep. It works, and we get what we need (al­though it ap­peared lat­er that this is not the op­ti­mal, fastest way).

  3. Im­ple­ment the whole thing. Easy.

I'm not sure why col­leges don't teach their stu­dents to think as IT pro­fes­sion­als. Why do law or psy­chol­o­gy stu­dents learn that, but not fu­ture de­vel­op­ers? It doesn't seem that dif­fi­cult to teach, and is damn use­ful dur­ing the whole ca­reer. Why would any uni­ver­si­ty pre­fer wast­ing stu­dents' time teach­ing them PHP?

Be­cause of that, I've seen much more tal­ent­ed de­vel­op­ers with­out a de­gree than with one. Prob­a­bly be­cause the first ones know that it's not by learn­ing every name­space in .NET Frame­work or know­ing who Don­ald Knuth is that they will suc­ceed; stu­dents, on the oth­er hand, are trained to rely on learn-by-heart ap­proach­es, and just can't have an ef­fec­tive ap­proach of a prob­lem by them­selves.