我们应该雇佣一个用 Perl 写 C 的人吗? [英] Should we hire someone who writes C in Perl?

查看:35
本文介绍了我们应该雇佣一个用 Perl 写 C 的人吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个同事最近面试了一些求职者,其中一个说他们有非常好的 Perl 经验.

One of my colleagues recently interviewed some candidates for a job and one said they had very good Perl experience.

由于我的同事不了解 Perl,他要求我对那个潜在雇员(非现场)编写的一些代码进行评论,所以我看了一眼并告诉了他我的担忧(主要是它最初是没有评论,而且我们没有给他们足够的时间).

Since my colleague didn't know Perl, he asked me for a critique of some code written (off-site) by that potential hire, so I had a look and told him my concerns (the main one was that it originally had no comments and it's not like we gave them enough time).

然而,代码有效,所以我不愿意在没有更多输入的情况下说不.另一个问题是,这段代码基本上看起来和我用 C 编写的代码完全一样.自从我使用 Perl 已经有一段时间了(而且我没有做很多,我更像是一个快速脚本的 Python bod)但我似乎回想一下,这是一种比这家伙使用的语言更具表现力的语言.

However, the code works so I'm loathe to say no-go without some more input. Another concern is that this code basically looks exactly how I'd code it in C. It's been a while since I did Perl (and I didn't do a lot, I'm more a Python bod for quick scripts) but I seem to recall that it was a much more expressive language than what this guy used.

我正在寻找来自真正的 Perl 编码人员的意见,以及如何改进的建议(以及为什么 Perl 编码人员应该知道这种改进方法).

I'm looking for input from real Perl coders, and suggestions for how it could be improved (and why a Perl coder should know that method of improvement).

您还可以对使用完全不同的语言编写一种语言的人是否应该(或不应该被雇用)进行抒情.我对你的论点很感兴趣,但这个问题主要是为了批评代码.

You can also wax lyrical about whether people who write one language in a totally different language should (or shouldn't be hired). I'm interested in your arguments but this question is primarily for a critique of the code.

规范是按如下方式成功处理 CSV 文件并输出各个字段:

The spec was to successfully process a CSV file as follows and output the individual fields:

User ID,Name , Level,Numeric ID
pax, Pax Morgan ,admin,0
gt,"  Turner, George" rubbish,user,1
ms,"Mark \"X-Men\" Spencer","guest user",2
ab,, "user","3"

输出应该是这样的(潜在雇员的代码实际上是这样输出的):

The output was to be something like this (the potential hire's code actually output this):

User ID,Name , Level,Numeric ID:
   [User ID]
   [Name]
   [Level]
   [Numeric ID]
pax, Pax Morgan ,admin,0:
   [pax]
   [Pax Morgan]
   [admin]
   [0]
gt,"  Turner, George  " rubbish,user,1:
   [gt]
   [  Turner, George  ]
   [user]
   [1]
ms,"Mark \"X-Men\" Spencer","guest user",2:
   [ms]
   [Mark "X-Men" Spencer]
   [guest user]
   [2]
ab,, "user","3":
   [ab]
   []
   [user]
   [3]

这是他们提交的代码:

#!/usr/bin/perl

# Open file.

open (IN, "qq.in") || die "Cannot open qq.in";

# Process every line.

while (<IN>) {
    chomp;
    $line = $_;
    print "$line:\n";

    # Process every field in line.

    while ($line ne "") {
        # Skip spaces and start with empty field.

        if (substr ($line,0,1) eq " ") {
            $line = substr ($line,1);
            next;
        }

        $field = "";
        $minlen = 0;

        # Detect quoted field or otherwise.

        if (substr ($line,0,1) eq "\"") {
            $line = substr ($line,1);
            $pastquote = 0;
            while ($line ne "") {
                # Special handling for quotes (\\ and \").

                if (length ($line) >= 2) {
                    if (substr ($line,0,2) eq "\\\"") {
                        $field = $field . "\"";
                        $line = substr ($line,2);
                        next;
                    }
                    if (substr ($line,0,2) eq "\\\\") {
                        $field = $field . "\\";
                        $line = substr ($line,2);
                        next;
                    }
                }

                # Detect closing quote.

                if (($pastquote == 0) && (substr ($line,0,1) eq "\"")) {
                    $pastquote = 1;
                    $line = substr ($line,1);
                    $minlen = length ($field);
                    next;
                }

                # Only worry about comma if past closing quote.

                if (($pastquote == 1) && (substr ($line,0,1) eq ",")) {
                    $line = substr ($line,1);
                    last;
                }
                $field = $field . substr ($line,0,1);
                $line = substr ($line,1);
            }
        } else {
            while ($line ne "") {
                if (substr ($line,0,1) eq ",") {
                    $line = substr ($line,1);
                    last;
                }
                if ($pastquote == 0) {
                    $field = $field . substr ($line,0,1);
                }
                $line = substr ($line,1);
            }
        }

        # Strip trailing space.

        while ($field ne "") {
            if (length ($field) == $minlen) {
                last;
            }
            if (substr ($field,length ($field)-1,1) eq " ") {
                $field = substr ($field,0, length ($field)-1);
                next;
            }
            last;
        }

        print "   [$field]\n";
    }
}
close (IN);

推荐答案

我建议人们永远不要雇用 Perl 程序员、C 程序员或 Java 程序员等等.只雇佣好人.我聘请来编写 Perl 的程序员也精通各种其他语言.我聘用他们是因为他们是优秀的程序员,而且优秀的程序员可以处理多种语言.

I advise people to never hire Perl programmers, or C programmers, or Java programmers, and so on. Just hire good people. The programmers who I've hired to write Perl were also skilled in various other languages. I hired them because they were good programmers, and good programmers can deal with multiple languages.

现在,该代码确实看起来很像 C,但我认为 Perl 也很好.如果您正在招聘一名优秀的程序员,只要稍加练习 Perl,他就会迎头赶上.人们抱怨缺少正则表达式,这会使辅助区域的事情变得更简单,但我不希望任何人都有解析脏 CSV 数据的正则表达式解决方案.我不想阅读或维护它.

Now, that code does look a lot like C, but I think it's fine Perl too. If you're hiring a good programmer, with a little Perl practice under his belt he'll catch up just fine. People are complaining about the lack of regexes, which would make things simpler in ancillary areas, but I wouldn't wish on anyone a regex solution on parsing that dirty CSV data. I wouldn't want to read it or maintain it.

我经常发现反向问题更麻烦:聘请一个写好的Perl代码的好程序员,但团队的其他人只知道Perl的基础知识,跟不上.这与糟糕的格式或糟糕的结构无关,只是在高级主题(例如闭包)方面的技能水平.

I often find that the reverse problem is more troublesome: hire a good programmer who writes good Perl code, but the rest of the team only knows the basics of Perl and can't keep up. This has nothing to do with poor formatting or bad structure, just a level of skill with advanced topics (e.g. closures).

在这场辩论中事情变得有点激烈,所以我想我应该更多地解释一下我如何处理这种事情.我不认为这是一个正则表达式/无正则表达式问题.我不会像候选人那样编写代码,但这并不重要.

Things are getting a bit heated in this debate, so I think I should explain more about how I deal with this sort of thing. I don't see this as a regex / no-regex problem. I wouldn't have written the code the way the candidate did, but that doesn't really matter.

我也写了很多蹩脚的代码.在第一遍时,我通常更多地考虑结构和过程而不是语法.我稍后再回去把它收紧.这并不意味着应聘者的代码就很好,但是对于面试中的第一次通过,我并不会太苛刻地判断它.我不知道他有多少时间来写它等等,所以我不会根据我有很长时间工作的东西来判断它.面试问题总是很奇怪,因为你不能做你真正在实际工作中会做的事情.如果我必须从头开始并在 15 分钟内完成,我可能也无法回答有关编写 CSV 解析器的问题.确实,今天我浪费了比这更多的东西,因为我是一个有一些代码的笨蛋.

I write quite a bit of crappy code too. On the first pass, I'm usually thinking more about structure and process than syntax. I go back later to tighten that up. That doesn't mean that the candidate's code is any good, but for a first pass done in an interview I don't judge it too harshly. I don't know how much time he had to write it and so on, so I don't judge it based on something I would have had a long time to work on. Interview questions are always weird because you can't do what you'd really do for real work. I'd probably fail a question about writing a CSV parser too if I had to start from scratch and do it in 15 minutes. Indeed, I wasted more than that today being a total bonehead with some code.

我去看了 Text::CSV_PP 的代码,纯 PerlText::CSV_XS 的表亲.它使用正则表达式,但是很多正则表达式处理特殊情况,并且在结构上与这里提供的代码没有太大区别.代码很多,而且代码很复杂,我希望我永远不必再看一遍.

I went to look at the code for Text::CSV_PP, the Pure Perl cousin to Text::CSV_XS. It uses regular expressions, but a lot of regular expressions that handle special cases, and in structure isn't that different from the code presented here. It's a lot of code, and it's complicated code that I hope I never have to look at again.

我倾向于不喜欢只针对给定输入的面试答案.在现实世界中,这几乎总是错误的做法,在现实世界中您必须处理您可能尚未发现的案例,并且您需要灵活地处理未来的问题.我发现 Stackoverflow 上的很多答案也缺少这一点.解决方案的思考过程对我来说更能说明问题.人们更容易掌握一门语言,而不是改变他们对事物的看法.我可以教人们如何编写更好的 Perl,但我不能在大多数情况下改变他们的软件.那来自伤疤和经历.

What I tend to disfavor are interview answers that only address the given input. That's almost always the wrong thing to do in the real world where you have to handle cases that you may not have discovered yet and you need the flexibility to deal with future issues. I find that missing from a lot of answers on Stackoverflow too. The thought process of the solution is more telling to me. People become skilled at a language more easily than they change how they think about things. I can teach people how to write better Perl, but I can't change their wetware for the most part. That comes from scars and experience.

因为我不是在那里看候选人编写解决方案或问他后续问题,所以我不会推测他为什么这样写.对于我在这里看到的其他一些解决方案,我在采访中可能会同样苛刻.

Since I wasn't there to see the candidate code the solution or ask him follow-up questions, I won't speculate on why he wrote it the way he did. For some of the other solutions I've seen here, I could be equally harsh in an interview.

职业是一段旅程.我不希望每个人都成为大师或拥有相同的经历.如果我因为人们不知道某些技巧或习语而注销他们,我不会给他们继续旅程的机会.候选人的代码不会赢得任何奖品,但显然足以让他进入最后三名以供考虑.那家伙站起来尝试了,比我一生中见过的许多代码都要好得多,这对我来说已经足够了.

A career is a journey. I don't expect everyone to be a guru or to have the same experiences. If I write-off people because they don't know some trick or idiom, I'm not giving them the chance to continue their journey. The candidate's code won't win any prizes, but apparently it was enough to get him into the final three for consideration for an offer. The guy got up there and tried, did much better than a lot of code I've seen in my life, and that's good enough for me.

这篇关于我们应该雇佣一个用 Perl 写 C 的人吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆