Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: A question about method return values and error checking

by mr_mischief (Monsignor)
on Nov 04, 2015 at 15:47 UTC ( #1146911=note: print w/replies, xml ) Need Help??


in reply to A question about method return values and error checking

I think you're asking writers of code you're calling to consider the code around it, which is code you're writing. Why don't you read the documentation for code you call and be prepared for it to return what it's documented to return? The code you write is your responsibility, not the responsibility of those providing properly documented libraries to you.

If you want to introduce a code shim around the library call that allows you to handle the undef differently and return something else, then feel free to do that. Don't try to call out the library's implementors as doing the wrong thing. They told you what their code does. You chose to call it. From there your code is your responsibility, not theirs.

Given the opportunity to write code that does it the same way as Sys::Info::OS or another way, choose either. Then document what your code returns and why. Then people can decide whether to use your code or not, and perhaps can blame you for their code doing the wrong thing after they ignore its documentation.

I just read the documentation for the module, and it doesn't promise that the name method returns a defined value nor does it clearly say it may return undef. I'm sure the author would appreciate a POD patch. Meanwhile, there are is_linux, is_bsd, is_windows, and is_unknown methods to test in a boolean manner for each of those. Have you tried those methods? Are you depending upon code you're unsure of working the way you're using it?

If you read the fairly simple code of Sys::Info::OS to understand what it does, you'd see it's checking against Sys::Info::Constants's OSID value for those boolean methods. In the name method, it's deferring to Sys::Info::Driver::Linux::OS in the case of Linux, which in turn defers in its private _populate_os_version method to Sys::Info::Driver::Linux::OS::Distribution. That module does a best guess by reading the conventional (and LSB-required) informational files in /etc and /proc to determine the system name, version, edition, and more. The synopsis of Sys::Info::Driver::Linux::OS::Distribution very clearly shows that its name method returns a false value if it can't determine the OS. The description clearly states which distributions it does currently support, and welcomes patches.

This document describes version C<0.7903> of C<Sys::Info::Driver::Linux::OS::Distribution> released on C<8 May 2013>. This is a simple module that tries to guess on what linux distribution we are running by looking for release's files in /etc. It now looks for 'lsb-release' first as that should be the most correct and adds ubuntu support. Secondly, it will look for the distro specific files. It currently recognizes slackware, debian, suse, fedora, redhat, turbolinux, yellowdog, knoppix, mandrake, conectiva, immunix, tinysofa, va-linux, trustix, adamantix, yoper, arch-linux, libranet, gentoo, ubuntu and redflag. It has function to get the version for debian, suse, redhat, gentoo, slackware, redflag and ubuntu(lsb). People running unsupported distro's are greatly encouraged to submit patches.

Instead of complaining about the author who did all that work so you could use a single method not returning exactly what you think it should, why don't you either do the work yourself, handle the return value properly for what you're getting, or contribute to his project? Patches are "greatly encouraged" and I think you've volunteered to submit some quite well.

Replies are listed 'Best First'.
Re^2: A question about method return values and error checking
by wee (Scribe) on Nov 06, 2015 at 17:33 UTC

    The world is better place if you're not rude to strangers.

    Give that a try sometime.

      Presuming strangers owe you their time is among the most rude things one can do. If you don't like the free and open code provided, don't use it. If you don't like my advice, you don't have to follow it.

      Now you're not just complaining about the free and open code. Now you're complaining that I pointed out in my thorough review of your situation that you were complaining about the free and open code.

      So far as I can tell from reading the thread, I've put more time into understanding and fixing your problem than you have. I'm pretty certain the group as a whole has spent more person-hours on this than you have. Frankly, I think that's rude of you.

      Nothing requires me to help you at all. Neither requires the other members here to help, either. You're ranting about a stranger to strangers and expecting them not only to help you for free, but apparently to agree with you as well. Here's the thing: when you're wrong (and I do think you're wrong) agreeing with you doesn't help. Disagreeing with you isn't an attempt to be rude. It's an attempt to make your situation better in the long run even if it's a little uncomfortable for you now.

      Then after all the free time people here have put into trying to help you with your complaint about the free code you're using to make your living, you make an entire new response to tell me you don't like the tone you read into my advice? Which one of us exactly is being rude?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2022-12-03 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?