现在的位置: 首页 > 综合 > 正文

为什么程序员不会编程?

2011年03月23日 ⁄ 综合 ⁄ 共 2265字 ⁄ 字号 评论关闭

  人生真的很有意思,三年前我坐在面试官的位置上,面试别的程序员,现在我坐在程序员的位置上,等待被别人面试。

 

  三年前我跟朋友合作在厦门开始创业,做对欧美的软件外包开发。当时困扰我们最大的问题之一就是找不到会编程的程序员。往往收到四,五十份简历,到最后只有一两个应聘者能通过我们的编程测试。其实测试的题目也不难,像bubble sort之类的问题。现如今,从荷兰回来,需要找一份工作,却发现找到一家好的公司好的工作也不容易。最近通过博客园的招聘板块,投出去一些简历,也陆续接到一些面试的反馈。

 

  在为即将来临的面试作准备的时候,发现网上的一篇文章《Using FizzBuzz to Find Developers who Grok Coding》里面讲到,

  After a fair bit of trial and error I’ve come to discover that people who struggle to code don’t just struggle on big problems, or even smallish problems (i.e. write a implementation of a linked list). They struggle with tiny problems.

  So I set out to develop questions that can identify this kind of developer and came up with a class of questions I call “FizzBuzz Questions” named after a game children often play (or are made to play) in schools in the UK. An example of a Fizz-Buzz question is the following:


  Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.


  Most good programmers should be able to write out on paper a program which does this in a under a couple of minutes.Want to know something scary ? – the majority of comp sci graduates can’t. I’ve also seen self-proclaimed senior programmers take more than 10-15 minutes to write a solution.


  这段文字的大意是讲到作者在面试程序员的时候发现那些不会解决编程小问题的程序员通常也不会解决技术中的大问题。所以他设计了一道面试题目,可以帮助他发现不会编程的程序员。题目是这样的,写一个程序打印出1到100之间的整数,如果这个整数能被3整除,用"Fizz"替换这个数字,如果这个整数能被5整除,用"Buzz"替换这个数, 如果这个数能被3和5同时整除, 用"FizzBuzz"来替换这个数. 好的程序员应该在几分钟之内写出这样的程序. 但是让作者感到恐怖的是, 大多数计算机专业毕业的学生都没有办法在几分钟之内写出这个程序. 而且有些自诩是高级程序员的程序员也花了超过10~15分钟的时间来完成这段程序.


  为了测试以下自己是不是会编程的程序员, 我也赶紧地打开Visual Studio, 5分钟后, 版本1出世, F5, 打印出 1 2 Fizz 3 4 Buzz .... (心中暗想应该先写测试的, 没有TDD), 然后赶紧回到代码发现自己的逻辑错误, 修改, 2分钟后, 运行,  1 2 Fizz 4 Buzz .... 还好, 结果正确, 虽然是没有Unit test. 再看看代码, 有点长, Refactor 一下, 搞定.


  你是一个会编程的程序员吗? 不防也做做这道"FizzBuzz"的面试题目, 记得纪录一下你的时间哦.


我的"FizzBuzz" C# version


1 using System;
2  using System.Linq;
3
4  namespace FizzBuzz
5 {
6 class Program
7 {
8 static void Main(string[] args)
9 {
10 var numbers = Enumerable.Range(1, 100);
11 foreach (var number in numbers)
12 {
13 if (number%3 == 0 && number%5 == 0)
14 {
15 Console.WriteLine("FizzBuzz");
16 }
17 else if (number % 3 == 0)
18 {
19 Console.WriteLine("Fizz");
20 }
21 else if (number % 5 == 0)
22 {
23 Console.WriteLine("Buzz");
24 }
25 else
26 {
27 Console.WriteLine(number);
28 }
29 }
30 Console.ReadKey();
31 }
32 }
33 }
34  

 

更新(2010.11.11 00:55) :

Jeff Wong 在他的文章 <也谈求职中的fizz-buzz-thing,兼谈程序员为什么不会编程>中对本文是个很好的补充. 代码也比较简洁, 跟评论中六楼童同的比较类似.

 

 

抱歉!评论已关闭.