Re: [PW-dev] parameter names (dash, underscore, none)
Status: Alpha
Brought to you by:
spadkins
From: Cees H. <ce...@si...> - 2001-06-19 23:19:23
|
On Tue, 19 Jun 2001, Stephen Adkins wrote: > Hi, > > I continue to work on the next mini-release of the > Perl Widget Library. I have incorporated a number > of parameters from style sheets such as "border-style", etc. > > Usage looks like this. > > $last_name = $wc->widget( > -name => "last_name", > -widget_class => "Widget::HTML::TextField", > -size => 8, # from HTML spec > -maxlength => 18, # from HTML spec > -color => "#6666CC", # from CSS spec > -font_size => "10px", # from CSS spec > -border_style => "solid", # from CSS spec > -border_width => "1px", # from CSS spec > -border_color => "#6666CC", # from CSS spec > -padding => "2px", # from CSS spec > -background_color => "#ccffcc", # from CSS spec > -font_family => "Verdana, Geneva, Arial", # from CSS spec > -override => 1, # increase precedence of options to > "override" from "default" > -validate => "date", # "date", "time", "datetime", "enum", > "number", "integer", ":regexp" > )->html(); > > However, this presents a stylistic dilemma with parameter names. > If I use "border-style", the syntax would be > > $last_name = $wc->widget( > -border-style => "solid", > )->html(); > > However, this fails because "-border-style" cannot be a bareword. > I have so far opted to changed dashes in attribute names to underscores. > This is the first option. I think in these situations it is best to look at solutions that other developers have opted for. Personallly, I don't like underscores. That is how I define private menthods, so it just doesn't seem right. Also, since the CGI.pm module uses '-', it could confuse people. When do i use _ and when do I use -. JavaScript has this same problem with stylesheets and accessing styles from within code. They opted for removing the middle dash and using an UC letter (ie -border-style becomes -borderStyle). I think it is more user-friendly to be consistent with related languages and modules in this case (people are likely to use a mix of Widget.pm, CGI.pm and Javascript in the same project), then to come up with yet another different way of doing things. Cees |