Thread Lesbarkeit von Code (35 answers)
Opened by bloonix at 2006-12-01 18:05

bloonix
 2006-12-01 18:05
#72156 #72156
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Hallo Community,

hin und wieder mache ich mir nicht nur Gedanken um guten Code,
sondern auch um schönen. Was haltet ihr von

Code: (dl )
1
2
3
4
5
6
7
8
9
10
sub struct {
  return
     ref($_[0])
        ? ref($_[0]) eq 'HASH'
           ? $_[0]
           : croak "not a hash ref"
        : @_ & 1
           ? croak "odd number of elements in hash"
           : {@_};
}


oder ist dieses Beispiel viel lesbarer?

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
sub struct {
  if (ref($_[0])) {
     if (ref($_[0]) eq 'HASH') {
        return $_[0];
     } else {
        croak "not a hash ref";
     }
  } elsif (@_ & 1) {
     croak "odd number of elements in hash";
  } else {
     return {@_};
  }
}


Was würdet ihr bevorzugen? :)

Gruss,
opi\n\n

<!--EDIT|opi|1164989242-->
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.

View full thread Lesbarkeit von Code