刚才去thoughtworks面试,被结结实实的鄙视了一把,不过输的心服口服!

若鱼1919 2011-07-14 03:54:23
之前他们给发了一个笔试题,我把代码写好以后就发给他们了。今天主要是对我的代码现场进行重构。他们之所以如此的喜欢重构,大概跟《重构》的作者Martin Fowler就在这家公司有关系吧。
我的代码有这么一个方法:

public void setPoint(Point point){
int x = point.getX();
int y = point.getY();
int new_x = x;
int new_y = y;
if(x<LOWER_LEFT_POINT.getX()){
new_x = LOWER_LEFT_POINT.getX();
}
if(x > UPPER_RIGHT_POINT.getX()){
new_x = UPPER_RIGHT_POINT.getX();
}
if(y < LOWER_LEFT_POINT.getY()){
new_y = LOWER_LEFT_POINT.getY();
}
if(y > UPPER_RIGHT_POINT.getY()){
new_y = UPPER_RIGHT_POINT.getY();
}
this.point = new Point(new_x,new_y);
}

他们就说,有没有看出来你的代码里面存在重复代码?我是楞没看出来。然后,他就手动抽出来一个方法,就在这个时候连IDE都提示说有重复代码了,可我还是没看出来!逗得那两个GG笑得很开心。然后我就越心虚。最后,他从这段代码抽出两个方法,然后改了改方法里的局部变量名,这时候我才发现,这两个函数是一模一样的,汗死了!再往后,很多已经不再是某个小细节的问题了。
那个GG对我的评价是,基本上不具备的面向对象的设计和分析能力。虽然这么说有点伤感情,但是心服口服,本来以为自己对面向对象还算了解吧,看来还有很长一段路要走啊!
把原题发给大家看看:

MARS ROVERS
A squad of robotic rovers are to be landed by NASA on a plateau on Mars. This plateau, which is curiously rectangular, must be navigated by the rovers so that their on-board cameras can get a complete view of the surrounding terrain to send back to Earth.
A rover's position and location is represented by a combination of x and y co-ordinates and a letter representing one of the four cardinal compass points. The plateau is divided up into a grid to simplify navigation. An example position might be 0, 0, N, which means the rover is in the bottom left corner and facing North.
In order to control a rover, NASA sends a simple string of letters. The possible letters are 'L', 'R' and 'M'. 'L' and 'R' makes the rover spin 90 degrees left or right respectively, without moving from its current spot. 'M' means move forward one grid point, and maintain the same heading.
Assume that the square directly North from (x, y) is (x, y+1).
INPUT:
The first line of input is the upper-right coordinates of the plateau, the lower-left coordinates are assumed to be 0,0.
The rest of the input is information pertaining to the rovers that have been deployed. Each rover has two lines of input. The first line gives the rover's position, and the second line is a series of instructions telling the rover how to explore the plateau.
The position is made up of two integers and a letter separated by spaces, corresponding to the x and y co-ordinates and the rover's orientation.
Each rover will be finished sequentially, which means that the second rover won't start to move until the first one has finished moving.
OUTPUT
The output for each rover should be its final co-ordinates and heading.
INPUT AND OUTPUT
Test Input:
5 5
1 2 N
LMLMLMLMM
3 3 E
MMRMMRMRRM
Expected Output:
1 3 N
5 1 E

...全文
1991 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
24K純帥 2011-07-14
  • 打赏
  • 举报
回复
嘿嘿,这么重构确实很蛋疼。。
老张-AI 2011-07-14
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 wujiafan51 的回复:]

我有一个问题!他把题目发给你了。你做好后又发给他了。然后他又要你过去。。
我不懂了。他看了你的代码觉得不行。为什么还要你过去。。。他是故意的吗????
[/Quote]

故意让楼主过去调戏一把,然后打击一下你,提高一下他们公司的知名度,

这不,楼主就来CSDN提高他们知名度了
wujiafan51 2011-07-14
  • 打赏
  • 举报
回复
我有一个问题!他把题目发给你了。你做好后又发给他了。然后他又要你过去。。
我不懂了。他看了你的代码觉得不行。为什么还要你过去。。。他是故意的吗????
scare111 2011-07-14
  • 打赏
  • 举报
回复
你的方法的确有那么点问题
从问题描述,和你的方法来看。
你的SETPOINT所处理的问题就只有一个
不要越界。。。就 OK了!
所有方法,都是一个 private int handleOverFlow(int max,int value)....
你重复的判断了。。很多,而且不用四个点表示的。。plateau,设定个长和宽就好了。。
。。
。。。
。。。。最后说句,这玩意有用吗????哪TMD那么多时间重构。。学院派啊。。
。老外总是搞。。OVER DESIGN。。
把简单问题复杂化。。何必呢?。。
zn85600301 2011-07-14
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 healer_kx 的回复:]

不用feel shame,很多人很学院派,这些人都没有怎么参加过实际项目都说不定呢。
[/Quote]

他们将代码 从艺术的角度看 并不是从项目的角度看
aotian16 2011-07-14
  • 打赏
  • 举报
回复
来学习下吧
healer_kx 2011-07-14
  • 打赏
  • 举报
回复
不用feel shame,很多人很学院派,这些人都没有怎么参加过实际项目都说不定呢。
kai27ks 2011-07-14
  • 打赏
  • 举报
回复
国外的公司就是不了解中国国情呐。。要重构写的就不快。写的慢领导就说你能力有问题。。
healer_kx 2011-07-14
  • 打赏
  • 举报
回复
thoughtworks是那个靠忽悠人赚钱的公司嘛?
zn85600301 2011-07-14
  • 打赏
  • 举报
回复
一般工程只赶进度 要不代码写的特别乱和冗繁 很少有人去重构

62,634

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧