• Russ (unregistered)

    It never ceases to amaze me how many people don't know the constructs that are available to them in the programming language and are too lazy to google what they need.

    Edit: fist

  • jxl (unregistered)

    Long live Fortran and COBOL

    Edit: Finger

  • Cable (unregistered) in reply to Russ
    Russ:
    It never ceases to amaze me how many people don't know the constructs that are available to them in the programming language and are too lazy to google what they need.

    Edit: fist

    Oh yeah google it, that solves stupidity. In my experience mostly people in forums post (in case of a really hard problem) the last statement, thx I solved it myself, without mentioning how they did it. That doesn't make it easier for a lazy guy like me ;)

  • (cs)

    "It's so easy to use the Fortran system call; is there even a way to execute command-line programs from C++?"

    Yep:

    int system( const char *command );
    That is the beauty of C++ - you get C's stuff with it. :)

    ...cut 75 minutes off the average execution time of this particular program. (With no reference point, I don't know how good that is.)

    ANY performance improvement is a performance improvement. Not to mention the reduction of overall system overhead incurred by starting external processes, etc.

  • Axit (unregistered) in reply to jtwine
    jtwine:
    >That is the beauty of C++ - you get C's stuff with it. :)
    And by far it's greatest weakness.
  • mav (unregistered)

    Psh. Unix. Whatever, its OK I guess, if you don't have access to an IBM System i. OS/400 FTW.

  • (cs)

    As someone who is just learning Python (as in I just found the man pages and am reading the introduction), it's not always obvious what to look for.

    Of course, if you have half a brain, you can always enter a couple of combinations of: "How do you <x> in <Language>?" into Google...

  • (cs) in reply to mav
    mav:
    Psh. Unix. Whatever, its OK I guess, if you don't have access to an IBM System i. OS/400 FTW.

    Did you even bother to look at the article?

  • Strider (unregistered) in reply to jtwine
    jtwine:
    > ...cut 75 minutes off the average execution time of this > particular program. (With no reference point, I don't > know how good that is.)

    ANY performance improvement is a performance improvement. Not to mention the reduction of overall system overhead incurred by starting external processes, etc.

    scratches head I'm not getting what you're trying to rant about here. He's simply saying that -75mins cannot be converted to a percentage improvement without a total mins...i.e. -75m/80m vs. -75m/2,000,000m so without that reference point he doesnt know how good of an improvment that is...

    so what are you arguing about??

  • Unomi (unregistered)

    I think the Perl philosophy 'TIMTODI' can leave some bad examples too.....

    • Unomi -
  • Toralf (unregistered)

    I'd prefer '$my_filesize = (stat($file))[7]'

  • alephnull (unregistered)

    I must confess that I have written similar code and deployed it in 'production' once. It was because the Perl we had was compiled without large-file support while the Solaris binutils did.

    It was supposed to be temporary until we upgraded Perl, but it's still there for all I know.

  • Unomi (unregistered) in reply to Cable
    Cable:
    Russ:
    It never ceases to amaze me how many people don't know the constructs that are available to them in the programming language and are too lazy to google what they need.

    Edit: fist

    Oh yeah google it, that solves stupidity.

    I think many programs has a 'man page' for this very purpose. If you're stupid enough not to read it, you better don't start scripting without knowing any possibilities left.

    I comes down to know wich path to check first. RTFM, ask a co-worker, read the homepage of the program (maybe updates of the manual), google for specific howto's (and test them first), ask in forums, pray....

    • Unomi -
  • Alex G. (unregistered)

    Bleh. That's what happens when you force some guy who does bash to do Perl.

    This is common. What bothers me is that everyone seems to say it's the fault of the Unix design, which is not true. It's just to fault of people who don't use it correctly, just like the old Java rants, etc etc etc.

  • Ohnonymous (unregistered)

    Python:

    os.stat('somefile').st_size

  • Smitty (unregistered)

    Oh, I get it, that's what makes perl so 'powerful', it's non-intuitive use of shorthand whenever and wherever possible.

    How would one EVER guess that the supplied code solved that problem. Where would you look to find the '-s' operator (or whatever perl twinks call it.)

    What the hell is wrong with

    $filesize = size_on_disk(filename); or some equally intuitive and easily remembered (or guessed) function name ?

    perl sucks - get over it.

  • booya (unregistered)

    !first

  • Gary (unregistered) in reply to Smitty

    I couldn't agree more. Perl's shorthands are horribly difficult to understand. I much prefer Ruby short hands. They make so much more sense.

  • Nex (unregistered) in reply to Smitty
    Smitty:
    Oh, I get it, that's what makes perl so 'powerful', it's non-intuitive use of shorthand whenever and wherever possible.

    How would one EVER guess that the supplied code solved that problem. Where would you look to find the '-s' operator (or whatever perl twinks call it.)

    What the hell is wrong with

    $filesize = size_on_disk(filename); or some equally intuitive and easily remembered (or guessed) function name ?

    perl sucks - get over it.

    Yea perl sucks...hence why it is still in use by some of the largest websites (and highly popular to date).

  • (cs) in reply to Smitty
    Smitty:
    Oh, I get it, that's what makes perl so 'powerful', it's non-intuitive use of shorthand whenever and wherever possible.

    How would one EVER guess that the supplied code solved that problem. Where would you look to find the '-s' operator (or whatever perl twinks call it.)

    What the hell is wrong with

    $filesize = size_on_disk(filename); or some equally intuitive and easily remembered (or guessed) function name ?

    perl sucks - get over it.

    I hate perl 5 (perl6 may turn out okay) as much as anyone, especially weird stuff like -s.

    But.... it is using sed instead of perl's built in regex stuff that is so lame of this code. That and doing in system calls what the language was designed to replace. :)

    edit : also, as for the timing - 75 mins is quite a big improvement no matter how long the program takes. I mean no program is going to take 20,000 hours is it? So 75 mins must be quite a chunk of time.

  • diaphanein (unregistered) in reply to snoofle
    snoofle:
    As someone who is just learning Python (as in I just found the man pages and am reading the introduction), it's not always obvious what to look for.

    Of course, if you have half a brain, you can always enter a couple of combinations of: "How do you <x> in <Language>?" into Google...

    import os statinfo = os.stat('somefile.txt') statinfo (33188, 422511L, 769L, 1, 1032, 100, 926L, 1105022698,1105022732, 1105022732) statinfo.st_size 926L

    http://docs.python.org/lib/os-file-dir.html

  • (cs) in reply to Smitty
    Smitty:
    What the hell is wrong with

    $filesize = size_on_disk(filename); or some equally intuitive and easily remembered (or guessed) function name ?

    Perl has stat, but part of Perl's job is to function as a functional superset of shell scripts, awk, and sed, which is where all the weird filetests come from. In fact, I would never have even considered using a filetest like that, and most Perl scripts don't.

    perl sucks - get over it.

    Considering the alternatives (shell scripting, sed, and awk) Perl sucks the least!

  • (cs) in reply to mkb
    Considering the alternatives (shell scripting, sed, and awk) Perl sucks the least!

    Ha! I want that on a t-shirt - "If you look at the alternatives, I suck the least!" :)

  • xzzy (unregistered)

    The best part is if the file size ever takes up less than 8 digits, you'll get characters from the file name in the output. Or if it runs over 8 digits, the file size gets truncated.

    The run time of the calling script is nowhere near as offensive as the fact that the pipe doesn't even work.

  • Olius (unregistered) in reply to snoofle
    As someone who is just learning Python (as in I just found the man pages and am reading the introduction), it's not always obvious what to look for.

    You could try looking for the tutorials, then work through some examples, then get used to scanning reference pages on python.org then try to convert some of your old code to python for a bit of a laugh then try a few small projects using python instead of bash or C...

    It's a shame that so many people these days confuse "knowing how to find the answer" with "asking google", let alone "asking a BB".

    s/python/perl/g s/python/C/g

  • Daniel (unregistered) in reply to Smitty
    Smitty:
    How would one EVER guess that the supplied code solved that problem.
    If you're guessing while programming (or scripting, what ever), then you should probably think about doing something else.
    Smitty:
    What the hell is wrong with $filesize = size_on_disk(filename)
    Well why not filesize($file), or size_of_file($file) etc etc. That doesn't solve the problem, it just makes it "easier" in your happy little hypothetical world.
  • Daniel (unregistered) in reply to Smitty
    Smitty:
    How would one EVER guess that the supplied code solved that problem.
    If you're guessing while programming (or scripting, what ever), then you should probably think about doing something else.
    Smitty:
    What the hell is wrong with $filesize = size_on_disk(filename)
    Well why not filesize($file), or size_of_file($file) etc etc. That doesn't solve the problem, it just makes it "easier" in your happy little hypothetical world.
  • Chris (unregistered)

    Was the university so prestigious that they even taught spelling?

    pirates of Penzance!

  • diaphanein (unregistered) in reply to mkb
    mkb:
    Smitty:
    perl sucks - get over it.

    Considering the alternatives (shell scripting, sed, and awk) Perl sucks the least!

    If that's the only set you consider, then yes. There are (other) scripting languages that don't suck, that aren't cryptic, that don't inherently lend themselves unreadable, unmaintainable code.

  • (cs) in reply to gilleain
    gilleain:
    Ha! I want that on a t-shirt - "If you look at the alternatives, I suck the least!" :)

    This meme has been around a while. A number of years ago I remember a quote from nugget or jwz or some similar programmer/pundit: "X Window is the second worst windowing system but all the others are tied for first."

  • ElQuberto (unregistered) in reply to Russ

    Had something similiar with a C/Java programmer writing some perl to copy a file by reading it into memory and then printing it out to another filehandle.

    I was really shocked to read it until I started programming in Java and saw that's the way you do it.

  • (cs) in reply to Unomi
    Unomi:
    I think the Perl philosophy 'TIMTODI' can leave some bad examples too.....
    • Unomi -
    I think you mean "TIMTOWTDI", though I've also seen it as "TIMTOWDI". Perhaps we should just refer to it as /TIMTOWT?DI/ ...
  • (cs) in reply to Smitty
    Smitty:
    Oh, I get it, that's what makes perl so 'powerful', it's non-intuitive use of shorthand whenever and wherever possible.

    How would one EVER guess that the supplied code solved that problem. Where would you look to find the '-s' operator (or whatever perl twinks call it.)

    What the hell is wrong with

    $filesize = size_on_disk(filename); or some equally intuitive and easily remembered (or guessed) function name ?

    perl sucks - get over it.

    I get confused when a French text uses abbreviations (that're recognised by anyone fluent in French, and are present in all modern French dictionaries)!!! Therefore French must suck!!!

    Grow up.

    Google is still your friend, even if you piss off everyone else.

  • (cs) in reply to diaphanein
    diaphanein:
    If that's the only set you consider, then yes. There are (other) scripting languages that don't suck, that aren't cryptic, that don't inherently lend themselves unreadable, unmaintainable code.

    Sure, but do they have the advantages perl has? -regular expressions -C-like syntax for easy adoption -large user base -large installed base on random machines

    The only one that comes close is Python, which isn't any more maintainable or readable than Perl.

    I've been programming in Perl for close to 10 years and I have yet to see code that I can't read except for an obfuscation contest.

  • (cs) in reply to ElQuberto
    ElQuberto:
    Had something similiar with a C/Java programmer writing some perl to copy a file by reading it into memory and then printing it out to another filehandle.

    I was really shocked to read it until I started programming in Java and saw that's the way you do it.

    That's something that always drove me crazy in Java. Really? I can't connect an InputStream to an OutputStream directly? Not even in some special case?

  • Olius (unregistered) in reply to mkb
    I've been programming in Perl for close to 10 years and I have yet to see code that I can't read except for an obfuscation contest.

    ...Even in the first year of learning?

  • dnm (unregistered)

    I work with people who to this day think the best way to get the system time in perl is:

    $date = `date +%Y%m%d`;
    chop $date;
    
  • (cs) in reply to Nex
    Nex:
    Smitty:
    Oh, I get it, that's what makes perl so 'powerful', it's non-intuitive use of shorthand whenever and wherever possible.

    How would one EVER guess that the supplied code solved that problem. Where would you look to find the '-s' operator (or whatever perl twinks call it.)

    What the hell is wrong with

    $filesize = size_on_disk(filename); or some equally intuitive and easily remembered (or guessed) function name ?

    perl sucks - get over it.

    Yea perl sucks...hence why it is still in use by some of the largest websites (and highly popular to date).

    I'm not saying this in an attempt to attack or defend Perl...but, just because a lot of big sites use it doesn't necessarily mean it doesn't suck. I'm sure we could all identify heavily deployed applications/operating systems/programming languages that suck in one way or another. For example, I've spent a lot of time with (and enjoy working with) PHP. Everyone knows how badly that sucks (just check out then function names. WTF?!) but there are a large number of big sites that use it....

  • (cs) in reply to ElQuberto
    ElQuberto:
    Had something similiar with a C/Java programmer writing some perl to copy a file by reading it into memory and then printing it out to another filehandle.

    I was really shocked to read it until I started programming in Java and saw that's the way you do it.

    use File::Copy;
    copy $from, $to;

    As an added bonus, both parameters can be either a filehandle or a path.

  • dnm (unregistered) in reply to Smitty
    Smitty:
    Oh, I get it, that's what makes perl so 'powerful', it's non-intuitive use of shorthand whenever and wherever possible.

    How would one EVER guess that the supplied code solved that problem. Where would you look to find the '-s' operator (or whatever perl twinks call it.)

    What the hell is wrong with

    $filesize = size_on_disk(filename); or some equally intuitive and easily remembered (or guessed) function name ?

    perl sucks - get over it.

    Yes, because copying what BASH HAS ALREADY DONE FOR YEARS is what makes PERL stupid and unreadable.

    snicker

  • (cs) in reply to Irrelevant
    Irrelevant:
    Smitty:
    Oh, I get it, that's what makes perl so 'powerful', it's non-intuitive use of shorthand whenever and wherever possible.

    How would one EVER guess that the supplied code solved that problem. Where would you look to find the '-s' operator (or whatever perl twinks call it.)

    What the hell is wrong with

    $filesize = size_on_disk(filename); or some equally intuitive and easily remembered (or guessed) function name ?

    perl sucks - get over it.

    I get confused when a French text uses abbreviations (that're recognised by anyone fluent in French, and are present in all modern French dictionaries)!!! Therefore French must suck!!!

    Grow up.

    Google is still your friend, even if you piss off everyone else.

    Smitty does have one point, though. It is hard to find the -s operator using the man pages, provided all you know is that you want to find the size of a file. But then, how many other programming languages provide such information anywhere in the man files?

  • (cs) in reply to Nex
    Nex:
    Smitty:
    Oh, I get it, that's what makes perl so 'powerful', it's non-intuitive use of shorthand whenever and wherever possible.

    How would one EVER guess that the supplied code solved that problem. Where would you look to find the '-s' operator (or whatever perl twinks call it.)

    What the hell is wrong with

    $filesize = size_on_disk(filename); or some equally intuitive and easily remembered (or guessed) function name ?

    perl sucks - get over it.

    Yea perl sucks...hence why it is still in use by some of the largest websites (and highly popular to date).

    Plenty of companies still run programs written in COBOL. Care to take it for a spin?

  • (cs) in reply to Strider
    Strider:
    *scratches head* I'm not getting what you're trying to rant about here. He's simply saying that -75mins cannot be converted to a percentage improvement without a total mins...i.e. -75m/80m vs. -75m/2,000,000m so without that reference point he doesnt know how good of an improvment that is...

    Though it's PROBABLY pretty good. I don't think there are many applications where shaving an hour off runtime would be considered insignificant. Especially for a change this small.

  • (cs) in reply to Smitty
    Smitty:
    Oh, I get it, that's what makes perl so 'powerful', it's non-intuitive use of shorthand whenever and wherever possible.

    How would one EVER guess that the supplied code solved that problem. Where would you look to find the '-s' operator (or whatever perl twinks call it.)

    perldoc -f -X

    (perldoc, give me info on the functions (-f) of the form -X. actually, you can do -f on any of the things listed here and -X.)

    Anyone who's been programming Perl more than two or three weeks should know there's a bunch of file tests like this. Take a look at the Camel book. Or a cheat sheet. Or a tutorial, somewhere, for the love of God! It's not like they're trying to hide these things. DO WE NEED TO SPOON-FEED YOU? TAKE SOME INITIATIVE!!!

           -X      A file test, where X is one of the letters listed below.  This unary operator
                   takes one argument, either a filename or a filehandle, and tests the associated
                   file to see if something is true about it.  If the argument is omitted, tests $_,
                   except for "-t", which tests STDIN.  Unless otherwise documented, it returns 1
                   for true and ’’ for false, or the undefined value if the file doesn’t exist.
                   Despite the funny names, precedence is the same as any other named unary opera-
                   tor, and the argument may be parenthesized like any other unary operator.  The
                   operator may be any of:
    
                       -r  File is readable by effective uid/gid.
                       -w  File is writable by effective uid/gid.
                       -x  File is executable by effective uid/gid.
                       -o  File is owned by effective uid.
    
                       -R  File is readable by real uid/gid.
                       -W  File is writable by real uid/gid.
                       -X  File is executable by real uid/gid.
                       -O  File is owned by real uid.
    
                       -e  File exists.
                       -z  File has zero size (is empty).
                       -s  File has nonzero size (returns size in bytes).
    
                       -f  File is a plain file.
                       -d  File is a directory.
                       -l  File is a symbolic link.
                       -p  File is a named pipe (FIFO), or Filehandle is a pipe.
                       -S  File is a socket.
                       -b  File is a block special file.
                       -c  File is a character special file.
                       -t  Filehandle is opened to a tty.
    
                       -u  File has setuid bit set.
                       -g  File has setgid bit set.
                       -k  File has sticky bit set.
    
                       -T  File is an ASCII text file (heuristic guess).
                       -B  File is a "binary" file (opposite of -T).
    
                       -M  Script start time minus file modification time, in days.
                       -A  Same for access time.
                       -C  Same for inode change time (Unix, may differ for other platforms)
    

    Addendum (2007-04-05 10:53): Hey, try PHP! You not only get neat functions like

    diskfreespace()
    you get ones like
    disk_free_space()
    as well!

    cough cough hack hack

  • and i don't even like perl (unregistered) in reply to Smitty
    Smitty:
    How would one EVER guess that the supplied code solved that problem. Where would you look to find the '-s' operator (or whatever perl twinks call it.)

    Because that's how you do it in a shell script, and Perl was designed to appeal to people whose previous experience was mostly shell scripting.

    Smitty:
    What the hell is wrong with

    $filesize = size_on_disk(filename); or some equally intuitive and easily remembered (or guessed) function name ?

    Well, you could always use the stat($filename) function.

    Or if you prefer something object oriented, you could look into the File::stat module for an OO interface to the same thing.

    Or you could realize that Perl has a number of very serious flaws, chief among them are morons like yourself, Smitty.

  • dkf (unregistered) in reply to bstorer
    bstorer:
    Unomi:
    I think the Perl philosophy 'TIMTODI' can leave some bad examples too.....
    • Unomi -
    I think you mean "TIMTOWTDI", though I've also seen it as "TIMTOWDI". Perhaps we should just refer to it as /TIMTOWT?DI/ ...
    So there's more than one way to abbreviate "There's More Than One Way To Do It"? Figures...
  • anne (unregistered) in reply to dnm
    dnm:
    I work with people who to this day think the best way to get the system time in perl is:
    $date = `date +%Y%m%d`;
    chop $date;
    

    (this line is a workaround for weird bug where the first line after a quote appears in the quote)

    yeah, they should be using 'chomp'!

    just kidding. although I've seen this done a lot around here, too. I even do it occasionally if I"m in a hurry and I need to do something in perl that was already done in bash.

    am I totally weird for loving perl AND bash? they both have their strong points. I have to say I get all excited when I realize I have a little repetitive job that would be much better as a bash script. sometimes my bash scripts even have perl in them!

  • (cs) in reply to dnm
    dnm:
    I work with people who to this day think the best way to get the system time in perl is:
    $date = `date +%Y%m%d`;
    chop $date;
    

    Ack! They're supposed to chomp! ;)

  • AnonY (unregistered) in reply to ElQuberto

    Well on one hand yes & on the other no. You do not have to read the entire file into memory, just have a little byte[] buffer (4k is more than adequate) in the middle to fire it off to the output stream. Or if you are feeling very lazy then use commons-io's FileUtils.copyFile() method. Thanks to that method (well the IOUtils equivalent) I can copy/move files all over the place in Java just as fast as anything else.

  • Steve (unregistered)

    The supercilious superior tone of many of the comments here really bugs me.

    It's not as if we weren't all newbies at one time in our lives. Perhaps some of use learned Perl and C++ at our father's knee but many of use came to these things later along in life.

    As I mentioned before in another comment, sometimes, when you're new to a programming language or even a whole new software environment (such as making the transition from a Windows box to Unix, which is a pretty radical jump), sometimes you don't know how to frame the right question because you don't have all of the vocabulary down.

    Yes, Google and other search engines make life much easier these days (think of those of us who learned to program with a copy of the FORTRAN Language Manual, a Programmer's Guide, and the IBM System/360 Principles of Operation as our only guides) but Google also produces a lot of noise, chaff, and downright wrong answers, too.

Leave a comment on “The UNIX Philosophy”

Log In or post as a guest

Replying to comment #:

« Return to Article