avatar
speaking of crappy code# Java - 爪哇娇娃
m*t
1
This here is a great source for your daily laugh:
http://www.thedailywtf.com
My favorite one from thedailywtf is something like this:
if (aBool == true) {
aBool = true;
} else {
aBool = true;
}
avatar
h*d
2
once I saw this in production code
if (true) {
do blah blah blah...
}

【在 m******t 的大作中提到】
: This here is a great source for your daily laugh:
: http://www.thedailywtf.com
: My favorite one from thedailywtf is something like this:
: if (aBool == true) {
: aBool = true;
: } else {
: aBool = true;
: }

avatar
c*t
3
Once I was given a task to modify a piece of Java applet code by
a web artist to add some new functionalities. In numerous places,
it had codes like:
if ((a + b) == 1)
c = z + d + e + a;
else if ((a + b) == 2)
c = z + d + e + a + 1;
else if ((a + b) == 3)
c = z + d + e + a + 2;
else if ((a + b) == 4)
c = z + d + e + a + 3;
else if ((a + b) == 5)
c = z + d + e + a + 4;
I only made changes in one place where I had to add new code.

【在 m******t 的大作中提到】
: This here is a great source for your daily laugh:
: http://www.thedailywtf.com
: My favorite one from thedailywtf is something like this:
: if (aBool == true) {
: aBool = true;
: } else {
: aBool = true;
: }

avatar
A*o
4
这个可以理解为当时条件作废了,
同理,也经常看见:if(false){...}

【在 h**d 的大作中提到】
: once I saw this in production code
: if (true) {
: do blah blah blah...
: }

avatar
A*o
5
another one is:
if(...){...}
else{
a = getValue();
}
a = a = getValue();
and it's written by my coworker... :(

【在 c*****t 的大作中提到】
: Once I was given a task to modify a piece of Java applet code by
: a web artist to add some new functionalities. In numerous places,
: it had codes like:
: if ((a + b) == 1)
: c = z + d + e + a;
: else if ((a + b) == 2)
: c = z + d + e + a + 1;
: else if ((a + b) == 3)
: c = z + d + e + a + 2;
: else if ((a + b) == 4)

avatar
c*t
6
Could be that if-block has same named variables as its parent.

【在 h**d 的大作中提到】
: once I saw this in production code
: if (true) {
: do blah blah blah...
: }

avatar
g*g
7
我现在最烦的是这种代码
private int foo;
private void a() {
foo = ...;
}
private void b() {

... = foo;
}
一整个类的函数基本就没有传入传出参数。所有需要的地方都用类变量,
让我想起C时代喜欢用全局变量的。偏偏一个类动则2-3k行,不停地需要
回到头上去看定义。
还有那种util类,根本不需要也没有constructor,所有调用的地方都来个
new Blah().execute(),就是不肯写成静态函数。

【在 A**o 的大作中提到】
: another one is:
: if(...){...}
: else{
: a = getValue();
: }
: a = a = getValue();
: and it's written by my coworker... :(

avatar
h*d
8
nope...hehe very simple logic:)

【在 c**t 的大作中提到】
: Could be that if-block has same named variables as its parent.
avatar
h*d
9
我曾经做过的一个项目,
一个人写得所有method都是final,他eclipse就直接这么设好了
另一个人是个method就public static

【在 g*****g 的大作中提到】
: 我现在最烦的是这种代码
: private int foo;
: private void a() {
: foo = ...;
: }
: private void b() {
:
: ... = foo;
: }
: 一整个类的函数基本就没有传入传出参数。所有需要的地方都用类变量,

avatar
c*m
10
这种代码也能生存阿?我觉得在server side的development, 第一个需要考虑的就是
thread safety.

【在 g*****g 的大作中提到】
: 我现在最烦的是这种代码
: private int foo;
: private void a() {
: foo = ...;
: }
: private void b() {
:
: ... = foo;
: }
: 一整个类的函数基本就没有传入传出参数。所有需要的地方都用类变量,

avatar
A*o
11
你也太小瞧烂码的生存能力了。

【在 c*m 的大作中提到】
: 这种代码也能生存阿?我觉得在server side的development, 第一个需要考虑的就是
: thread safety.

avatar
s*e
12
Once a while I tried to clean up a project written by a brilliant consultant
. he open a connection pool for each db he wants to access, he pass the ref
to the mainframe all the way down to its four generations of children just
want to place the new gui window to the right spot. he used abstract factory
and factory method pattern whenever he liked to code that way.:)
avatar
m*t
13

consultant
ref
factory
I don't think I get it - how are the connection pool and the abstract
factory bad things?

【在 s******e 的大作中提到】
: Once a while I tried to clean up a project written by a brilliant consultant
: . he open a connection pool for each db he wants to access, he pass the ref
: to the mainframe all the way down to its four generations of children just
: want to place the new gui window to the right spot. he used abstract factory
: and factory method pattern whenever he liked to code that way.:)

avatar
s*e
14
first both connection pool and abstrct factory are good if you use them
wisely.
But too many connection pools can use unnecessary resources on both client/
business and EIS tiers. This can hurt your performance on both sides. In a
cucurrent env, you app can slow down and finally just hang up. you really do
not want more than one connection pool(more than one configuration) if not
necessary even you want to hit multiple dbs. This is true even you want to
do cross db join.
abstract factory pattern
avatar
m*t
15
Oh I see. I'm not sure about the connection pool part. If the connection
configuration is defined at pool level, I'm not sure how we can connect to
multiple dbs in one pool. Maybe we have different understanding on how
connection pools work.
As for abstract factory, I see your point. Although I would tend to think of
it as a style difference - some people would like to leave the door open
for the future, even if that means a little bit over-designing.

do
not
.

【在 s******e 的大作中提到】
: first both connection pool and abstrct factory are good if you use them
: wisely.
: But too many connection pools can use unnecessary resources on both client/
: business and EIS tiers. This can hurt your performance on both sides. In a
: cucurrent env, you app can slow down and finally just hang up. you really do
: not want more than one connection pool(more than one configuration) if not
: necessary even you want to hit multiple dbs. This is true even you want to
: do cross db join.
: abstract factory pattern

avatar
s*e
16
I am not sure if we have different understanding of connection pool or not.
what I know is if the multiple dbs run under the same db server and the db
server supports cross db join, there is no point for me to have more than on
connection pool, in other words, I only need one single configuration file.
Eyeing on the future is good. But you do not want to do this everywhere in
your code. especially for abstract factory, you do not want ot use it just
because you forsee in the future you might inj
avatar
m*t
17
Yes, we _are_ talking about different things. If you have multiple DB
instances running in the same server, and you only need one set of
configuration to connect, of course one pool would suffice. Especially in
your case you actually run queries across these "DBs", then logically they
are the same DB from the application standpoint.

on
file.
abstract

【在 s******e 的大作中提到】
: I am not sure if we have different understanding of connection pool or not.
: what I know is if the multiple dbs run under the same db server and the db
: server supports cross db join, there is no point for me to have more than on
: connection pool, in other words, I only need one single configuration file.
: Eyeing on the future is good. But you do not want to do this everywhere in
: your code. especially for abstract factory, you do not want ot use it just
: because you forsee in the future you might inj

avatar
wy
18
This one is really good:
Long id = obj.getId();
obj.setId(id);

【在 h**d 的大作中提到】
: 我曾经做过的一个项目,
: 一个人写得所有method都是final,他eclipse就直接这么设好了
: 另一个人是个method就public static

avatar
c*t
19
Just got code from a collaborator, he had code like
public void setXXXX (boolean variable)
{
variable = variable;
}
in at least 4-5 places. There are instance variables of the same name.
I am not even sure if that is intentional since some of these functions
got referenced a lot and the overall the code seems working (very shaky,
but fine as demo).
Funny that he talked all day when we had video conferences or meetings.
He was saying things like modules, libraries, modularity, etc and bragging

【在 m******t 的大作中提到】
: This here is a great source for your daily laugh:
: http://www.thedailywtf.com
: My favorite one from thedailywtf is something like this:
: if (aBool == true) {
: aBool = true;
: } else {
: aBool = true;
: }

avatar
g*g
20
Well, treat his stuff as a blackbox, ask him to specify the interface
and unit test before you do anything. That way, if you get caught,
you get caught early.

【在 c*****t 的大作中提到】
: Just got code from a collaborator, he had code like
: public void setXXXX (boolean variable)
: {
: variable = variable;
: }
: in at least 4-5 places. There are instance variables of the same name.
: I am not even sure if that is intentional since some of these functions
: got referenced a lot and the overall the code seems working (very shaky,
: but fine as demo).
: Funny that he talked all day when we had video conferences or meetings.

avatar
m*t
21

Well, "code wizards" usually don't do what you ask them to, but only what
they feel like to - which unfortunately typically doesn't include defining
contracts or unit-testing.

【在 g*****g 的大作中提到】
: Well, treat his stuff as a blackbox, ask him to specify the interface
: and unit test before you do anything. That way, if you get caught,
: you get caught early.

avatar
h*d
22
I doubt if they could provide unit test for this code.
Also I don't know how this code was written,
maybe this guy does not use IDE at all...
Interface is a good way....
just mock his code in your unit test.
But for integration tests, good luck:)

【在 g*****g 的大作中提到】
: Well, treat his stuff as a blackbox, ask him to specify the interface
: and unit test before you do anything. That way, if you get caught,
: you get caught early.

avatar
g*g
23
I didn't make it clear, of course the Master wouldn't do the
unit test, that's the extra work. But provide an interface and
specify (at least verbally) what the interface does shouldn't be
that difficult, and you do unit test for him.

【在 m******t 的大作中提到】
:
: Well, "code wizards" usually don't do what you ask them to, but only what
: they feel like to - which unfortunately typically doesn't include defining
: contracts or unit-testing.

avatar
h*d
24
I prefer not to do unit test for other people's code.
Worst case...I treat their code as black box, and write some module(
integration) tests.

【在 g*****g 的大作中提到】
: I didn't make it clear, of course the Master wouldn't do the
: unit test, that's the extra work. But provide an interface and
: specify (at least verbally) what the interface does shouldn't be
: that difficult, and you do unit test for him.

avatar
m*t
25

One rule I have always enforced whenever I have control over a team is this
- no matter how busy you are, or how much of a big shot you think you are,
you unit-test your own code.

【在 h**d 的大作中提到】
: I prefer not to do unit test for other people's code.
: Worst case...I treat their code as black box, and write some module(
: integration) tests.

avatar
h*d
26
nod,
my statement: unittest is part of the code, period. no arguement:)

this

【在 m******t 的大作中提到】
:
: One rule I have always enforced whenever I have control over a team is this
: - no matter how busy you are, or how much of a big shot you think you are,
: you unit-test your own code.

avatar
p*p
27
r u taking about me, Sir? :)))

consultant
ref
factory

【在 s******e 的大作中提到】
: Once a while I tried to clean up a project written by a brilliant consultant
: . he open a connection pool for each db he wants to access, he pass the ref
: to the mainframe all the way down to its four generations of children just
: want to place the new gui window to the right spot. he used abstract factory
: and factory method pattern whenever he liked to code that way.:)

avatar
p*p
28
what is unittest? JUNIT? any book or artical about it

【在 h**d 的大作中提到】
: nod,
: my statement: unittest is part of the code, period. no arguement:)
:
: this

avatar
h*d
29
Junit or testNG. hehe

【在 p***p 的大作中提到】
: what is unittest? JUNIT? any book or artical about it
avatar
p*p
30
Is there any good tutoriu or example of JUNIT online? google some
either too simple or to complicate

【在 p***p 的大作中提到】
: what is unittest? JUNIT? any book or artical about it
avatar
h*d
31
junit is very straightforward ah....you don't really need tutorials:)
You may want to take a look at easymock or jmock too

【在 p***p 的大作中提到】
: Is there any good tutoriu or example of JUNIT online? google some
: either too simple or to complicate

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。