Gentoo Archives: gentoo-perl

From: dams <dams@g.o>
To: gentoo-perl@l.g.o
Subject: Re: [gentoo-perl] g-cpan patch
Date: Tue, 12 Sep 2006 19:04:23
Message-Id: 20060912211054.0c13973c@localhost
In Reply to: Re: [gentoo-perl] g-cpan patch by Christian Hartmann
1 On Mon, 11 Sep 2006 11:34:23 +0200
2 Christian Hartmann <ian@g.o> wrote:
3
4 > > - recoded the small options verification
5 >
6 > Looks good.
7 >
8 > > - implemented a Fake CPAN::Frontend, to catch the output of the CPAN search
9 >
10 > Eek! That's an awful hack. That's not how code looks like I want to maintain.
11 > E.g. the 'package Gentoo::CPAN::FakeFrontend' part.
12
13 It doesn't look like a hack for me. Before coding that, I've looked carefully at the CPAN code, and it's obvious (at least for me) that the author thought about people willing to implement their own Frontend to CPAN.pm, for integration purpose. Now, our search should actually use something more backend-ish, but I didn't want to dig too much in the cpan code.
14
15 Anyway, my opinion is that creating a frontend for cpan is the good way(tm), when you want to interact with high level features of CPAN.pm.
16
17 >
18 > > - added a small spin animation to the cpan search
19 >
20 > I think I don't like spinners but I'm actually not really sure about that one.
21
22 Actually, I also usually dislike spinners. That's the stuff that need a way to be tunred off. But I thiought it was a good thing to let the user know that something is being done.
23
24 > Spinners just cause the process to take longer than it would take anyways
25 > without a spinner. (I'm pretty much against everything these days so don't
26 > take me too seroius on this one. ;)) Nevertheless I put that in a module
27 > called Gentoo::Portage::UI::Spinner so it can be reused this way e.g.:
28 >
29 > my $spinner=Gentoo::Portage::UI::Spinner->new();
30 > for (my $i=0;$i<5;$i++)
31 > {
32 > $spinner->spin();
33 > sleep(1);
34 > }
35 > $spinner->reset();
36 >
37 > Yeah.. overhead.. but reusable and more easy to read.
38
39
40 No, I'm all for it ! I would have coded UI::Spinner, but I wasn't sure you would accept the spinner concept in the first place.
41
42 >
43 > Anyways. The whole Gentoo::Portage stuff needs to be ripped out (of g-cpan,
44 > up2date-ng, mgtool, demerge, perl-info and some of my other endless and
45 > nameless tools/hacks) and put together nicely in a neat and slick module. I'm
46 > currently working on it. - Ok, ok.. I'm short of time but anyways.. -
47
48 Agreed. I think the author of ufed is also willing to do that. And I have a lot of code to handle USE flags and cascading profiles in profuse and flagedit. I should probably take it from flagedit and put it in Gentoo::Portage. (btw, use flagedit, it's a killer-app :)
49
50
51 > If it's
52 > all set and done I'll commit it to our gentoo-perl svn, so that we can work
53 > on it together. One thing I'd like to see established until then is one
54 > documented and persistent coding style. Furthermore all functions/code should
55 > be documented and a complete api-documentation about Gentoo::Portage should
56 > be available. We need a todo-list, a feature-list and a roadmap. - Big
57 > words.. ;)
58 >
59 > I'm pretty serious about it. The reason I'm writing this is that I don't want
60 > to have it turning into another big and ugly hack. I want a clean and well
61 > documented api to access and manipulate portage using perl that all our
62 > little tools can use.
63
64 I agree. I code perl for 7 years now, and I have some experience about coding style and documentation. However, my experience and opinion are probably not the same as yours, so I don't want to oblige/force anything.
65
66 Here is a small rules I use :
67
68 - put { at the end of the line
69 - put a space between command (if foreach while ...) and the first parenthesis
70 - don't put a space between methods and their args
71 - put space around operators
72 - no space after the first ( and before the last )
73 - 4 space indentation (no tabs)
74
75 example of the above :
76 if ($foo = 1) {
77 do { $something }
78 method($param1)
79 }
80
81 now VERY important :
82 - never use more ( ) than needed, see 'man perlop' and learn that by eart
83 - always use '&&' and '||' for BOOLEAN tests. Use 'and' and 'or' for CONDITIONAL tests
84
85 This needs explanation :
86
87 Correct : open(FILE, "/tmp/foo") or die "damned!";
88 in this case the 'or' is like in english : "please open the file, or else, die."
89
90 Correct : if ($foo == 3 && $bar > 2) { ... } #this is a BOOLEAN test
91
92 Wrong : open(FILE, "/tmp/foo") || die; # it's not a BOOLEAN test
93
94 Wrong if ($foo == 3 and $bar > 3) {}
95
96 Correct :
97 foreach (1..10) {
98 is_ok($_) && looks_good($_) or next;
99 $_ < 5 and warn "hm, number is < 5, continuing\n";
100 }
101
102 good handling of 'and', 'or', '&&', '||' allows to be more expressive, and to reduce useless ()
103
104
105 The rest of the list of rules :
106 - never use 'unless', never use 'until'
107 - never the suffix 'if'. insted of
108 do_something() if $ok write
109 $ok and do_something().
110 The order of "condition", then "action" is the same as if($ok) { do_something() }
111 - remove useless ';' (before a } )
112 - private things must start with a underscore : sub _privatemethod { } or $self->{_privateattr}
113
114 There are some others, but I cannot remember them yet, I have to code to remember :)
115
116
117 >
118 > For now I'm asking you not to commit anything until I've got that
119 > Gentoo::Portage thing ready. - BUT please don't stop hacking on it and coming
120 > up with ideas and stuff. :)
121
122 I wouldn't recommand this decision. When new people come and propose a patch and commit, it's usually not good to ask them to stop working/commiting : you'll demotivate them quickly. Better do a branch, and remerge. But let us some sandbox at least.
123
124 >
125 > I just want to ensure that all our efforts go in the same direction.
126
127
128 I'm willing to refactore and document the whole code, once we have decided rules and todos. Oh, about documentation, please please please, don't go into "dowegen stuff", or "huge header for every methods (even one liners)". I would recommend :
129
130 - use POD, use all the features of it.
131 - Document INLINE, not a but pod at the end of the file (use =cut to ... cut your pod :)
132 - be nice with the coder : have mandatory to document every single piece of pulic API, but don't be too strict with public methods.
133
134
135
136 I'm going to have 3 heavy weeks, but then I'll be able to code a lot. During that time, I would be happy to share ideas/remarks, especially about coding style and todos.
137
138 I'll talk about new features we thought about with cab, in a next mail :)
139
140
141 cu
142 --
143 gentoo-perl@g.o mailing list