6 ms·
What do you mean by Perl functions being modeled after POSIX functions? My only points of reference are POSIX being a UNIX system specification which defines b
by i336_ 9y ago
What do you mean by Perl functions being modeled after POSIX functions?
My only points of reference are POSIX being a UNIX system specification which defines both a C language reference and system userspace specification. I also have a vague notion of POSIX specifying the fundamental behavior of shells.
I'm just not quite sure which point of reference to apply.
- falsedan 9y agoPerl has a core function called 'unlink', which maps directly to unlink(2). Same for stat, rmdir, link, etc. They're good for when you want something more than what the coreutils give you, but don't want to compile some C.
- i336_ 9y agoOooh, I see. Nice!
- maxlybbert 9y agoIf you want to read a directory, you use the functions opendir, readdir, and closedir. You can get a decent idea of what they do by looking at POSIX documentation. They have been modified to fit Perl better, so you still have to look at the Perl documentation as well. If you want to fork a process, you use the function "fork". If you want to call exec, Perl has it. You can even have the parent process wait on the child's pid. This isn't a big deal to everyone, but I like POSIX, and I like knowing that if I want to do something new, there's a good chance I can start with "how would I do it in C on a POSIX system?" I have many complaints about Java, and one is that their original standard library appears to have been modeled on early versions of MFC, even though Sun had access to a superior API, since they had plenty of experience with shipping a POSIX operating system.
- i336_ 9y agoI see what you mean. POSIX was basically a committee ratifying things that a bunch of systems people had come up with. So it gets to the point, it's reasonably concise, and there's little noise to wade through to do most things. Java was slowly designed by committee, taking inspiration from other languages. I just thought of something. Maybe it's relevant. IBM said "let make something totally different with this 8086 system, let's make everything open and not lock it down." Apple said "let's do something different with the Macintosh, let's enforce absolute control over the hardware and software so we can perfectly unify them." Maybe Sun got fed up with SunOS and said "let's make a language and runtime that's totally different - something so different that it resists influence by platform architecture."
- maxlybbert 9y agoI think Java's "all OOP, all the time" approach influenced their standard library design. I don't like the result. "Modernism was based on a kind of arrogance, a set of monocultural blinders that elevated originality above all else, and led designers to believe that if they thought of something cool, it must be considered universally cool. That is, if something's worth doing, it's worth driving into the ground to the exclusion of all other approaches. Look at the use of parentheses in Lisp or the use of white space as syntax in Python. Or the mandatory use of objects in many languages, including Java. All of these are ways of taking freedom away from the end user 'for their own good'. They're just versions of Orwell's Newspeak, in which it's impossible to think bad thoughts. We escaped from the fashion police in the 1970s, but many programmers are still slaves of the cyber police" ( http://m.linuxjournal.com/article/3394 http://m.linuxjournal.com/article/3394 ).
- i336_ 9y agoVery very interesting thoughts, thanks very much for this comment. Would +10 if I could. The article was an excellent read too. I've noticed that a lot of people around the 18-25 demographic (and some outside that range) have mental health issues that (among other catastrophes) cause detrimental effects to emotional development. I was thankfully able to get off this train myself using alternative therapies about ten years ago, but one of the things I observed about myself was a tendency to hone in on one specific idea present in something I was thinking about and then redefine what I was focusing on on the basis of and in terms of that idea, in many situations irreversibly discarding any other possible interpretations. I essentially didn't have the capacity to wield concepts that required careful balance between a series of discrete ideas. I wonder a lot about how much of the noise margin present in current research and work is caused by related developmental issues.
- hoytech 9y agoIn addition to what others have said, perl also directly exposes errno via $!: $ perl -E 'unlink("/etc/passwd"); say (0+$!)' 13 $ grep 13 /usr/include/asm-generic/errno-base.h #define EACCES 13 /* Permission denied */ Of course $! is a special dual-val so if you treat it as a string you get the nicer strerror(3) equivalent: $ perl -E 'unlink("/etc/passwd"); say $!' Permission denied That said, some people prefer autodie: https://metacpan.org/pod/autodie https://metacpan.org/pod/autodie
- i336_ 9y agoWow, interesting. The language has type coercion, and makes full use of it. I likey :D Thanks for the example too!
- cestith 9y agoIt actually goes a bit beyond type coercion. Larry Wall is a linguist. The language is actually contextual. There's numeric vs. string context for scalars and scalar vs. list context for assignments and returns. The list of features is impressive, but taken together all at once can be daunting. I think that's why there's so much distaste for it in certain camps. It's actually possible in a function to test whether the caller wants a single value or a list and adjust your return accordingly. It has anonymous functions. It has closures. It has map() and sort(), either of which apply a custom block of code to a list. You can easily write user-supplied functions that do that, too. It has dictionaries / associative arrays (called "hashes" in the community since that's how they are implemented), regular arrays, scalar values, and a number of different object systems from which to choose.