Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^9: Perl Best Practices

by wazoox (Prior)
on Jul 19, 2005 at 22:25 UTC ( [id://476287]=note: print w/replies, xml ) Need Help??


in reply to Re^8: Perl Best Practices
in thread Perl Best Practices

What do you mean? For me "mutable states" are stuff like loop indices. May you develop?

Replies are listed 'Best First'.
Re^10: Perl Best Practices
by Anonymous Monk on Jul 20, 2005 at 17:07 UTC
    From the articles...
    Every time you call a function that can raise an exception and don't catch it on the spot, you create opportunities for surprise bugs caused by functions that terminated abruptly, leaving data in an inconsistent state, or other code paths that you didn't think about.
    ...and...
    NotifyIcon CreateNotifyIcon() { NotifyIcon icon = new NotifyIcon(); icon.Text = "Blah blah blah"; icon.Visible = true; icon.Icon = new Icon(GetType(), "cool.ico"); return icon; }
    Here's what it might look like after you fix it to be correct in the face of exceptions:
    NotifyIcon CreateNotifyIcon() { NotifyIcon icon = new NotifyIcon(); icon.Text = "Blah blah blah"; icon.Icon = new Icon(GetType(), "cool.ico"); icon.Visible = true; return icon; }
    Note that the errors arise when the exception disrupts the sequencing of side effects. No side-effects (like state), no problems.
      Note that the errors arise when the exception disrupts the sequencing of side effects. No side-effects (like state), no problems.

      All right. But AFAIK only pure functional programming avoids side-effects, isn't it? ;) How reimplementing the exemple above with no side-effects (in Perl, Java, Python, C++...) is beyond me.

        Well, when you write your own code in a language like Perl or Java, you can always try to minimize and localize side-effects. That is, you can try to make most of your functions pure, reduce the need for looping by using higher order functions, doing I/O at the top levels, not willy-nilly in the bowels, etc. When it comes to libraries though, you're at the mercy of someone else. Them's the breaks.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://476287]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-03-19 04:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found