4 ms·
Unix is basically a REPL for the C programming language. Its more than a operating system, its actually a development environment. And most of the Unix utilitie
by kamaal 14y ago
Unix is basically a REPL for the C programming language. Its more than a operating system, its actually a development environment. And most of the Unix utilities that you see today are sum total of people trying to solve problems they faced repeateadly. There fore what you see is tiny utilities with a lot options each designed to solve both a operating system and a programming problem. That is precisely what helps people to write almost real looking programs by just sewing commands using the pipe.
I love the all the three points the author mentions, because together they form a a very powerful platform to work with and solve problems.
>>Why does ls have dozens of tangled options? Because users, even Unix users, are not overly fond of the first two points of the Unix philosophy. They don’t want to chain little programs together. They’d rather do more with the tool at hand than put it down to pick up new tools. They do appreciate the ideal of single-purpose tools that work well together, but not too strictly.
I don't agree with this. I can tell you that I just love Unix the way it is now. People feel they are messy because,as I said they always keep looking at them as commands and not as small programs that can be used together to solve problems. Most people don't realize this, because they don't know how to use it. It takes a lot of time to mature on the Unix platform. You have to learn what the commands do, then you need to go out and learn how to use them in combinations. Then you need to start learning the Unix way of representing data and transforming data to solve problems.
Like always most people don't realize the fact that data is a actually 'Text'. And not learning how to work with Text/Strings/Data generally creates all sorts of other problems. Although projects which are RDBMS heavy don't encounter them usually. But a lot of projects that are not DB heavy really pass through frustrating patches of time trying to figure out easy ways of representing, transforming and working with Data(Text). The most common format which is heavily abused are XML's. Followed by JSON these days. But in my experience if only they had learned how to use a little grep, cat, head, tail, sed, awk and learned to represent their data properly they would save themselves writing several hundreds to thousand lines of code. This problem is especially prevalent in the Java world. They are plagued with writing endless programs that actually do a subset of what sed or awk do. Its sad, but most people express shock and surprise while shown how their 500 line Java program is actually a one line sed command. Or how a simple awk command actually does what they spent a whole day writing. Not understanding Unix forces you just re implement Unix utilities badly!
Unix utilities were precisely invented to solve these kind of problems. In fact if you find yourself solving a problem a particular way, then ideally you should use a tool that can be programmed that particular way to solve the problem.
A tool like sed is implicitly designed to open files, iterate line by line, provide you with matching, manipulating, counting, printing abilities. It also contains variables to hold data, and do all other kinds of manipulations. If you were to keep writing programs in permutations of logic to perform each of these facilities specifically as needed(Which is pretty common, if your data is in files), you might as well just go ahead and learn sed. Because that will ensure you not just save on writing code, but will also save you time.
Now this is just sed, Awk can go further. It can help you do a lot more stuff. It gives you conditionals, more sharpened regexes, better ways of handling field separated data, variables, functions and much more. Combined with stuff like wc, less, cat, tr, xargs, grep, column etc you really get a full fledged programming language(Without even realizing that you have one :)) in which you can hack real fast without worrying about bugs.
The thing is 'Text' is actually data. And knowing how to play with Text and learning how to manipulate it well helps you solve problems elegantly, quickly and in a far more easier way than writing a specific program for each task.
As a final leap, you mature as a Unix programmer when you learn Perl. Its the King of scripting languages. You master Perl, you begin to truly appreciate the beauty of what it means to be a backend Unix programmer. Its a world whose beauty and power is known to those who program in it. It completes the total Unix equation and suddenly you recieve your enlightenement and realize why despite Unix's messiness it still is the best thing in the world.
Worse is Indeed, Better!
- bandy 14y agoPerl is a shining example of OP's complaint - it is the kitchen sink. Sure, it allows you to do a ton of things, most all of which duplicate standard UNIX™ commands (those you'd find in PWB or v7), wrapped in a syntax that makes APL programmers recoil in horror. The argument the OP is making is that Unix has fallen into doing things The DEC Way, with gigantic monolithic programs that not only perform their obvious function, but have been turned into one of those twenty-pound Swiss Army Knives that look pretty but no-one actually uses, because they're too heavy to lug around. Does ls really need to emphasize its output with color? Better yet, in a default scheme that's often near-unreadable in an xterm that's running with its default colors? (I thank CentOS4/RHEL4 for this stunning example) No, it doesn't. Looking at ls output in a rainbow of colors is just as opaque to someone who hasn't read the man page (and grokked the system config file(!) for ls) as are the old single-character flags (with the exception of '/') that the F option gave back in '81 on BSD. Unix won over VMS, LISPMs, TOPS-20, CMS, etc., and all of those people have migrated to our platform, resulting in the world we have today.
- kamaal 14y agoIsn't that the crux of why worse is better. Turns out there is a huge mismatch between real world needs and text books demands of elegance. Tools that seem to be massively monolithic are extremely helpful in solving problems and do them far too well to do them away. Every time I hear why some programming language is better than Perl, I always see some Utopian dreams being displayed as the only thing that every matters to a programmer and nothing else. In reality there are many competing demands a programmer has. And providing them all generally leads to 'Swiss Army Knife' kind of designs. Because you are trying to provide many things in a package(That is the demand and the requirement at the first place). That sort of design might not be text book elegant, but it is extremely helpful in the real world. There fore the 'beauty' and 'utility' design goals don't often match. This is the unfortunate problem every programmer to face sooner or later. A programmer has to abide by time, budget and some metric of quality every time. Alas many of those demands don't lead to goals which may require an elegant design. In early days of Unix, Lisp programmers used to call the problems Perl programmers solve, itself as stupid. Telling the user why his needs are invalid isn't a nice way to sell things.