Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Do good Perl practices carry over to other coding?

by bradcathey (Prior)
on Jan 20, 2004 at 17:06 UTC ( [id://322635]=perlmeditation: print w/replies, xml ) Need Help??

I have been lurking around the monastery for about 6 months, long enough to take a crack at summarizing the mantra around here as "be smart, safe, efficient, and innovative." There are the oft-mentioned admonishments to use modules, use strict, write tight but readable code, and to embrace newer methods (new word for the week, thanks to meryln: "autovivification").

My question is: do these "good practices" carry over to other types of coding/mark-up, like HTML?( I know that many around here don't view HTML as code, so "mark-up".) For example, the new "paradigm" in web mark-up is all about standards, XHTML, XML, and CSS. The trend is towards table-less structures, CSS rollovers, etc.

The reason I bring this up here at the monastery, is that I see lots of code examples in SoPW and other areas (I won't point any fingers, 'cause I need to "get the log out of my own eye") that reflect waning, often deprecated methods. But begs the question, should those monks who use Perl exclusively for web (as opposed to systems folks) take the lead in the latest good practices in page mark-up?

Judging from the "mantra" mentioned about, I would say "yes." My goal as a Perl programmer is to be smart, safe, efficient, and innovative. Why not in all areas of my work? Comments? Thanks.

—Brad
"A little yeast leavens the whole dough."

Replies are listed 'Best First'.
Re: Do good Perl practices carry over to other coding?
by talexb (Chancellor) on Jan 20, 2004 at 17:27 UTC

    I think good practices are something you get into when you start to work with computers for any extended length of time. I've been fiddling with computers since 1973. The bad habits I've discarded (I hope) are

    • Stupid or obscure variable names
    • Who cares about indentation!
    • We don't need no stinkin' backups!
    • Just jump in and starting coding!
    • Documentation is for wimps!
    The good habits that (I hope) I've retained are
    • Sensible variable names
    • Proper indentation and nesting
    • Use of RCS, CVS or at least saving the original before I start hacking
    • Some thoughtful meditation about the problem at hand -- ideally away from the keyboard
    • Documentation can save your butt -- just do it
    My good habits as a C programmer for fifteen years carried over nicely when I started learning HTML in 1997 and Perl in 1998. No, HTML is not a 'programming language' (since there is no concept of variables, looping, conditionals, and so forth) but I suppose you can say you 'code' in HTML -- since there are many ways to 'encode' material in order to come up with a 'result'.

    Alex / talexb / Toronto

    Life is short: get busy!

Re: Do good Perl practices carry over to other coding?
by Abigail-II (Bishop) on Jan 20, 2004 at 17:18 UTC
    Most good coding practices are language-agnostic. Being smart, safe, efficient or innovative isn't something that originated when people started coding Perl. Good programmers do smart things, they do it safe, efficient and are innovative, even if they have never written a single bit of Perl. They could be writing Java, C, Ada, Pascal, FORTRAN, Haskell, ML, Lisp or whatever.

    As for carrying over to HTML.... well, that's like asking whether your good practises of creating rockets carry over to folding paper planes.

    Abigail

      I agree and disagree. For the most part, "high level" good coding practices, such as: document inline, create useful abstractions, organize your code well, etc, can be applied to nearly any language. However, there are many (fairly general) good practices which cannot necessarily be applied everywhere or to any language.

      For example, using descriptive variable names or name-spaces: some languages put limits on your ability to do this, often by draconian identifer length limits.

      Another example is limiting side-effect. What is even meant by side-effect can be very different from one language to another, and the notion of where the grey line between good side-effect and bad side-effect is even more tightly coupled to the language in use.

      Anyway, that's just nit-picking, sorry, but the point I guess I meant to make is that "good practices" are something that has to be a little more specific than being "smart, safe, efficient and innovative." That's basically being "good, safe, good, and good" at programming (I give credit to "safe" because it's at least one thing on that list that isn't self-evident... but it is nearly so). I guess my point is that "good, safe, efficient, and innovative" are more like a philosophy or a mantra, than a good practice, and good practices do tend to be at least somewhat language specific.

      ------------ :Wq Not an editor command: Wq
Re: Do good Perl practices carry over to other coding?
by perrin (Chancellor) on Jan 20, 2004 at 18:15 UTC
    It sounds like your real question is "why doesn't everyone here use the very latest HTML tricks?" I suspect the answer is a mix of these:

    1. Some of us have been writing HTML for a long time and are still using it the way we learned it because it still works.
    2. There are a lot of people using browsers that don't support the stuff you're talking about.
    3. Most people can't be bothered to write high-quality HTML in some silly little example script.
    4. Many of us don't write very much HTML at all because we use templates and leave the HTML coding to people who are experts at it.
      Yay I'm with perrin on this. Often when we code a small fragment we just do it out of our heads, so you could get any version of HTML that we learned once. Besides, things like CSS and some of its tricks are not totally browser agnostic. It can be hard enough covering recent versions of IE and Netscape, not to mention Opera, Mozilla, FireBird and Konqueror. Notice I keep Mozilla and FireBird separate, their are differences!

      For a production app I will write minimal HTML code so I can prove out the code. Then the HTML/CSS guys start on it. Notice I mention guys, there are two of them to one of me doing the coding. We have just spent $40k for a client and we did a costing analysis last week. Per functional block of code and HTML/CSS (maybe three or four CGI::Application run modes and three or four templates) the average cost is approximately $400. Per block this represents about 2 hours of programmer time but around 5 hours of HTML/CSS time. This doesn't include 'overall design of the look of the site', this is a separate item in the billing. This is tweaking HTML and CSS to be browser agnostic and to cover differences from browser to browser.

      Good practices do carry over. Even to HTML, if you really have to do it yourself!

      Greed, parsimony, hubris and laziness should always characterise a programmer. But so should knowledge, precision, generosity and communication.

      jdtoronto

        ++ to that!. You forgot "impatience", though ;) (The second programmer's virtue, next to laziness and hubris...) I find myself spending far too much time with (D)HTML and enjoy a break at the Perl Monastery.

        --
        Allolex

Re: Do good Perl practices carry over to other coding?
by jplindstrom (Monsignor) on Jan 20, 2004 at 21:24 UTC
    Things I've learned from being a Perl programmer that I didn't know before but can apply outside the Perl domain:

    • That post-processed source can give you excellent documentation which still lives near the code.
    • To see somewhat high-level concepts such as strings, regexen, lists and hashes as natural solutions to certain kinds of problems.
    • Unix thinking.
    • That tests are extremely useful and it's the right thing to do.
    • That a quick edit-compile-run cycle makes a difference.
    • That dynamic languages give you more and different things than static languages.
    • To view re-use as a very natural thing.
    • That efficient syntax matters when it comes to readbilit and maintainability.

    /J

Re: Do good Perl practices carry over to other coding?
by Aragorn (Curate) on Jan 20, 2004 at 19:50 UTC
    Good programming practices make your work easier, and I find this “flows over” into other stuff that you do, like markup, configuration files, etc. That people use obsolete HTML in examples could be lack of knowledge of the latest and greatest. In practice, I think that the people who provide the examples just try to convey some information particular to the question. Just showing the essence of some technique almost never requires all the bells and whistles of CSS, for example.

    So the people using the obsolete methods in examples are on the safe (works everywhere) and efficient (just the basics) side. This may not be innovative, but is (IMO) smart ;-)

    Arjen

Re: Do good Perl practices carry over to other coding?
by revdiablo (Prior) on Jan 20, 2004 at 20:03 UTC

    If your Meditation is indeed asking "should we be as concerned with following good practices with our (X?HT|X)ML markup as with our Perl code?" then I absolutely agree. We should follow good practices in anything we do. If not, at least make a note along the lines of "this HTML is messy and ad-hoc. Use at your own peril."

    But if, as perrin also mentions, your Meditation is asking "should we use the 'latest HTML tricks' whenever possible?" then I might tend to disagree. Using tricks and using good common sense are completely different things. Perhaps I should have replied directly to him, but I think this is applicable to the main topic as well.

    My basic point is that common sense and good practice matter, no matter what your task (unless, of course, one of the requirements of your task is to throw common sense and good practice out the window, and accomplish it by any means necessary). If you can't apply them to the thing you're doing, perhaps you should stop doing it..

      I've enjoyed reading all the replies here, but revdiablo makes a couple of important distinctions.

      My original intent in this mediation falls somewhere between "should we follow good practices in whatever code we right?" and "shouldn't we be using the most up-to-date methods for HTML mark-up as we would do in Perl?". However, I never said "tricks." XHTML and CSS are not tricks, they are new standards and options for newer browsers, the myriad of incompatibilities and bugs notwithstanding (IMHO,in a perfect world, CSS would be a non-brainer). I would never suggest "the latest" over the one that makes the most sense for the application.

      I am now building sites that are table-less, for instance, but never at the expense of the design, functionality, deadline, or budget. If I can do it, and it works in the right browsers, I find CSS faster, cleaner, and easier.

      It didn't take me long after coming to PM to realize that my Perl code was terrible. And since then I have learned tons about making it better, on all counts. I feel that the monks here really push themselves as Perl coders, and to make things work. Shouldn't we push ourselves even if it's "lowly" HTML?

      Update: Added quotes to "lowly"--I don't think it's lowly, but serious coders might.

      —Brad
      "A little yeast leavens the whole dough."
        Shouldn't we push ourselves even if it's lowly HTML?

        Hmm. Your phrasing strikes a chord in me somewhere. The answer is a resounding yes. As the old adage goes, "anything worth doing is worth doing well". But what makes HTML "lowly"? Is it that it's not a programming pursuit?

        I believe that the fundamentals of good programming practice (simplicity, clarity, generality as the tpop mantra goes) have more to do with the programmer than the language they are programming in. If it's these "best practices" that you were referring to in your OP, then again, certainly they should carry over to other areas of your life (even non-programming ones). For instance, many programmers have highly organized minds that can cut right through the chaff to the heart of a problem. This ability has more to do with their general problem solving skills than with how they chose to implement a solution. (though how to implement a solution might be an interesting sub-problem)

        Shouldn't we push ourselves even if it's lowly HTML?

        Absolutely. I didn't mean to imply using that clean, semantic markup and CSS for layout were "tricks." I was simply quoting perrin's reply. I agree with you completely. To me, writing good HTML is important. Using CSS when applicable is important. Tables should be used to store tabular data, not to position elements. Using tables for layout is, in my opinion, something like using map in void context: it works, and sometimes that's all that matters, but it's really not the best in terms of style.

Re: Do good Perl practices carry over to other coding?
by Coruscate (Sexton) on Jan 20, 2004 at 22:10 UTC

    Re: HTML

    If this topic had come up a year or two ago, I would probably be answering the HTML aspect quite differently. Back then, I was of the opinion that throwing together larger web applications with a dirty CGI.pm based, horribly structured document1 was fine and that more attention should have been given to the coding behind the application. Jumping to the present time, I spend just about as much effort putting together valid XHTML and CSS templates as I do writing the code. It provides a relaxing state of mind knowing that you are consistent in everything that you do. There are many people who say "Oh well, it's only HTML, I don't want to spend time with something that is not even a coding/scripting language", and so they throw together an ugly beast. Which can wind up hurting in the end, especially in a full-blown web application. Remember, the user interface is a large portion of the project and deserves as much attention as the coding behind the application.

    1: I'm not saying that CGI.pm is incapable of generating valid, well-structured HTML. It is, however, extremely easy to misuse CGI.pm's features and wind up with results that are far less than pleasing to both the eye and the X?HTML validator.

      It is, however, extremely easy to misuse CGI.pm's features and wind up with results that are far less than pleasing to both the eye and the X?HTML validator.
      Of all the bugs in CGI.pm, the most common and recurring ones have been in the (x)html generating functions.
Re: Do good Perl practices carry over to other coding?
by Jenda (Abbot) on Jan 20, 2004 at 23:46 UTC

    I'll take your node a little differently that most of the others (and forget about HTML completely:-).

    "Did, in your case, the "good practices" (whatever they were in yor case) you learned while programming Perl and interacting with the comunity affect your other work?"

    The answer is definitely YES. I do write better code in other languages now (at least I believe so) after the comments and advices I got from the Perl folk, I do think put more thought into variable names and formating ... Basicaly I try to write everything as if it might end up on CPAN (and you don't want to embarrass yourself in front of everybody do you?).

    It's a bit hard to explain (and remember) what changed since it was a slow gradual process that took some years :-)

    (To get back to your HTML ... I'm lucky enough not to have to care about HTML, CSS or any of this. The only web stuff I do is only gonna be seen by a few admins using the very same browser so the looks do not matter and needn't be portable. The HTML code is all nicely formated, but it's just the good ole basics.)

    Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature

Re: Do good Perl practices carry over to other coding?
by thraxil (Prior) on Jan 21, 2004 at 05:56 UTC

    my bias may be significant, but i write clean XHTML and CSS for many of the same reasons that i try to write clean Perl.

    when approached correctly, semantic, straightforward XHTML using CSS for presentation increases the reusability of the different pieces (XHTML can be parsed and transformed with standard XML tools, CSS can be seperated from the content and re-used across the site or changed without having to touch the XHTML or the code that generates the XHTML), improves accessibility, makes maintenance easier (wading through nested tables is not my idea of a good time), and is faster to write once you've gotten out of the tag-soup mentality. and there really is no reason that you can't make it work in older browsers. if you have a nice, semantically marked up document, it should display in Mosaic or Lynx just fine (usually better than the tag-soup version). with an @import hack, you can keep the CSS rules that break NN4 from doing any harm.

    also, don't underestimate the usefulness of a validator. if you're trying to fix a layout bug, running the markup through a validator and fixing any errors it shows you should be the first step. often, making things validate will magically fix whatever problem you were having. i consider using a validator the equivalent of use strict; for HTML.

    that said, i also make use HTML::Template to keep all that seperate from the Perl code. the more layers, the better. with a proper setup, most layout changes can be made just by tweaking the site-wide CSS file. occasionally some frontend changes require touching the templates. and only changes to the actual application logic involve editting the Perl. (and there are probably other layers for the business logic and data persistence, etc.)

Re: Do good Perl practices carry over to other coding?
by punchcard_don (Beadle) on Jan 21, 2004 at 13:33 UTC
    The original question is posed backwards.

    It's not a question of "Do good Perl practices carry over to othe rcoding?", but rather "Do good coding practices carry over to Perl?". To which the answer is an obvious 'yes, of course, to a degree suited to the situation'.

    For a twenty line html page with nothing remarkable that anyone can understand in the blink of an eye, it would be a waste of resources to comission a pre-coding study, flowchart the process, create a coding standard, comment every line, and document testing and revisions. On the other hand, all that might prove very useful when putting together a 1,000-page website.

    But "preparation and documentation adapted to the situation" is a triste banality.

    As for embracing advances, the original question contains the conundrum: "be safe and innovate". "Stay dry and get wet". Everyone wants the advantages of the latest technology (the flexibility of dhtml, the styling and maintainability of CSS) with the reliability of HTML 1.0. So, once again, it's situation that tips the balance one way or the other. There is no hard and fast rule. One client wants to simply deliver data to their clients and reliability is paramount. Another is trying to catch the limited attention span of teenagers and flashiness is paramount. Another wants to be able to maintain pages internally so maintainability is paramount.

    In general, the only place unbendable rules are appropriate are in one's most basic definition of one's self, but that's another topic.....

      It's not a question of "Do good Perl practices carry over to othe rcoding?", but rather "Do good coding practices carry over to Perl?".
      Interesting point punchcard_don, but since this site caters to Perl, I think the original direction works best. But your point is well-taken.
      "be safe and innovate". "Stay dry and get wet"
      I meant "safe" as in "secure" as in untainting, using strict, etc. So, actually it is possible to be safe and innovative. However, your point about clients needing to get just get the job done is an important one. The mantra in our design firm has always been: "Communicate first, get cute second." Or, if it doesn't sell, what's the point.

      —Brad
      "A little yeast leavens the whole dough."
Re: Do good Perl practices carry over to other coding?
by Anonymous Monk on Jan 20, 2004 at 20:33 UTC
    1. Name a "Good Perl Programming" practice.
    2. Sorry, "use strict;" is not a "Good Perl Programming practice" it's basic sanity that is included in all decent languages by default. Pick another one.
    3. Sorry, proper code ecapsulation and descriptive variable naming have nothing to do with Perl. Name another one.
    4. Nope, map in void context is just simply an example of not forcing the computer to do useless work, no Perl here.
    5. Correct! There is no such thing as a "Good Perl Programming practice." There are only good programming practices that can be applied to Perl just like any other language.
    6. This concludes our lesson for the day.
Re: Do good Perl practices carry over to other coding?
by flyingmoose (Priest) on Jan 21, 2004 at 16:29 UTC

    To paraphrase the Blues-Breakers song I am listening to right now .... "All Your Coding Is Coding".

    Absolutely -- it's made me better, faster, and smarter. In some ways, since Perl is easy to make confusing, it's made me even more careful with other languages and side-effects of operations.

    The main point though -- nothing is more important than laziness, impatience, and hubris. However, it must be said, the laziness part that says "Hit CPAN!" is sorely missed in most languages!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://322635]
Approved by gmax
Front-paged by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-03-19 11:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found