10 ms·
Oh My Glob
- 10098 13y agoWas expecting a picture of LSP somewhere in the post, left disappointed :(
- deckiedan 13y agoThis is why I refuse to use perl (or SH or derivatives, or haskell, sadly) for system admin scripts: A new admin comes along in 3 years time, and doesn't know the difference between , \, \, $?, $@, $&, $$, or gets confused between [] type ifs and [[ ]] ifs and 'test -' type ifs in BASH. Or doesn't know which variety of escape quotes are needed for which variety of strings. Python has so much less "non-alphanumeric semi-random-combo" syntax. Even though often a 3 line perl script would do the job, I prefer a 20 line python script that is easy to grok.
- kamaal 13y ago>>Even though often a 3 line perl script would do the job, I prefer a 20 line python script that is easy to grok. Talking about a 3 line Perl script doesn't make a nice comparison. Multiply those numbers by a minimum of 1000. Now you have a 3000 line Perl script Vs 60000 line Python program. Suddenly you go from one person writing a Perl script,to 10 people writing the same in Python. I've written > 3000 line Perl scripts quite a few times.
- deckiedan 13y agoGood thought - the thing is, once it's over a certain size, I don't think that it continues with the same ratio. Once it's beyond the difference between a one-line regexp/fork-to-shell/reverese combo type thing that perl is so great at, most of the code becomes your actual business logic, and logic code I feel ends up being similar lengths in perl, ruby, python, and other similar languages. Python has more boilerplate to get at regexps, or calling external programs and doing stuff with the output, say - but it's explicit. Perl has a lot more built in, and hidden behind non-alpha syntax. Both are great languages, and both have their place. I much prefer python, but also find perl a very versatile and useful tool.
- Mithaldu 13y agoDue to Perl lending itself to easily creating DSLs, i often find it to be much more concise even with bigger programs, when porting from python to Perl. (And then i end up making the difference in line count by actually writing documentation.)
- kamaal 13y ago>>Once it's beyond the difference between a one-line regexp/fork-to-shell/reverese combo type thing that perl is so great at That's just the very start, the very beginning of what Perl is good at. Read this book called "Higher Order Perl" by Mark Jason Dominus. You will see why 60000 line Python program actually becomes a 3000 line Perl program. >>most of the code becomes your actual business logic, and logic code I feel ends up being similar lengths No, You must take a serious look at Perl. Please read the book I mentioned. Some languages do make it very easy to write short, powerful, clear succinct code. More importantly you need to work in situations where Perl can show its magic. I've written scripts in a week alone which were easily 6 month Java projects.
- gjm11 13y ago"Higher Order Perl" is a very good book. I do not believe that any substantial fraction of the things it shows would take anywhere near 20x as many lines of code in Python as in Perl; certainly none of the examples I just looked at would. Could you please (1) give a couple of concrete examples that don't involve regular expressions (yes, Perl is very good with hairy REs; no, very few 3000 line programs consist mostly of REs) and (2) indicate your level of expertise in Python? Thanks!
- Mithaldu 13y agoThe article doesn't even use magic variables, so what the hell are you on about? Also, even with largely text-based programming you can run into obscure issues very easily. See for example: if a in b.keys() vs. if a in b
- DHowett 13y agoI understand what you're getting at, but... A new admin comes along in 3 years time, and doesn't know the difference(...) ...just makes it feel like you're optimizing for the lowest common intelligence. It's not a mark on the language but rather one on the understanding of your potential successor. Would the same sysadmin who is unfamiliar with [[ vs [, or $ vs @, be handily equipped to do common system administration tasks? Rebuild a degraded software RAID array? Troubleshoot a faulty network interface? Chances are comparatively slim.
- lmm 13y agoI've met plenty of competent sysadmins who could definitely rebuild a degraded software RAID array or troubleshoot a faulty network interface, but didn't know perl. I've watched people who didn't know python edit existing python scripts and make the change they wanted. To be fair, I've seen the same thing happen with well-written perl scripts - but only the kind that don't use [[ vs [ or the hundreds of random $* variables.
- Mithaldu 13y ago> [[ vs [ What does that even mean? Thanks for the last bit though. Perl has been in heavy use since the late 80s and a LOT of shitty legacy Perl has been written, while the Modern Perl renaissance only started in 2005. Many people still think all Perl looks like legacy Perl 4 style code and it's an image that's been hard to get rid of.
- anon1385 13y ago>it's an image that's been hard to get rid of. Maybe because Perl 6 adds even more obscure and magical operators? http://www.ozonehouse.com/mark/periodic/ http://www.ozonehouse.com/mark/periodic/
- Mithaldu 13y agoPerl 6 has nothing whatsoever to do with Perl 5 v18. Perl 6 cannot even execute code written for Perl 5 v18 (or any previous versions of Perl 5). It's a different language. However, people don't care to look and judge books by their cover, so you're probably right that it's a part of the reason.
- camus2 13y agowhat about ruby ? i find it much more closer to a shell script or perl than python , i think it's an good use case for admin scripts.
- kanatohodets 13y agoGreat article! Wish I'd found it a few months ago when I was reading HOP and trying to wrap my head around subroutine installation using globs. One of my favorite design elements of perl is the ability to lexically declare "Ok, now for some magic!" (aka "no strict 'refs';") while keeping strict checking in effect throughout the rest of the code.
- justbaker 13y agoOh my glob an AdventureTime reference on HN..
- jgalt212 13y agoLately, there seems to be an uptick in Perl posts on HN. Does anyone else notice this? Is something afoot amongst the monks?