6 ms·
I worked briefly at a shop that maintained a complex outsourced project by Yahoo (some ad bidding optimizations pipeline). As it turns out, they used Perl, one
by forgetfulness 3y ago
I worked briefly at a shop that maintained a complex outsourced project by Yahoo (some ad bidding optimizations pipeline).
As it turns out, they used Perl, one of the few sanctioned languages at Yahoo.
The coding style handed over from the client forbade every other thing that Perl fans tell you that make the language warm and endearing to them; you were allowed to use about a few of the sigil variables, all the data structures were to be used in their "object reference" form, because it sidestepped the "contexts" functionality of Perl, which was to be avoided at all costs.
I remember the tedium of having to maintain your own stacktrace, because all you got was a the `$@`, `$!` and `$?` variables, which contained precisely the last of various types of error encountered during execution within the process. If you encountered errors while performing error handling, the original error would be lost, so you had to keep a backup.
Edit: man, the contexts, the fans sweared by them, making analogies to natural language; I'm sorry to sound elitist, but they often came across as enthusiastic amateurs rather than people with a formal background in Computer Science. They claimed that things like passing an array to a place where an integer is expected to get the length was richness, not insanity.
- xupybd 3y agoI'm also shock that in Perl you can alter your return type based on the type of variable the caller is putting your result in. https://perlmaven.com/wantarray https://perlmaven.com/wantarray That always appeared as madness to me. Why would you make things that cryptic to understand?
- jsrcout 3y agoAs a Perl developer, I never once used that feature. It does make some sense in the context of how Perl's own operators work, making them "do the right thing" for different cases. But for user code... not needed.
- HybridCurve 3y agoThis branch of comments has decent gripes. I adopted the contextual thinking fairly easily so it was not an issue for me but having worked with so many languages since perl I can see why this would be annoying to others. It's not the most unfortunate aspect though.
- xupybd 3y agoIt's not so bad when you know what is going on but when you first hit something like that it's hard to figure out what is going on. Basically violating the Principle of least astonishment https://en.wikipedia.org/wiki/Principle_of_least_astonishment https://en.wikipedia.org/wiki/Principle_of_least_astonishmen...
- DonHopkins 3y agoPerl also flagrantly violates the Principle of Least Nausea, with all its emetic Syntactic Syrup of Ipecac. https://en.wikipedia.org/wiki/Syrup_of_ipecac https://en.wikipedia.org/wiki/Syrup_of_ipecac
- HybridCurve 3y agowantarray() is a sensing operation that allows a type of transparent function overloading: Oh you wanted just a scalar? OK. Python's ordered arguments mixed with out of order labeled arguments is worse IMO: Tell me arguments in this order. Or not... I mean, you could just tell me which they are. Wait, I got two of these... F*ck this, I quit
- xupybd 3y agoYes but if you want to know an arrays length you can just put it in a scalar. So you consume some API and want to get the length of the result. You put the array result into a scalar variable. Then what this is not the length?
- HybridCurve 3y agoThe API documentation should reflect that the result is context sensitive. Not reading that is a good way to get burned despite the language. Perl is well known for it's multitude of idiosyncrasies, this is one of the reasons why it can be frustrating to programmers who have better experience in more modern or rigidly structured languages.
- 3y ago
- bloak 3y agoIf a Perl script is written and maintained by just one person, or a few people who can agree with each other, then features like that are not a problem: you just agree not to use them. They are, however, an argument for not using Perl for a big project that lots of people will work on.
- brabel 3y ago> I'm also shock that in Perl you can alter your return type based on the type of variable the caller is putting your result in. You can do that in Java, if I understand that feature correctly. For example, it's possible to write a method that returns a generic type over whatever type you're trying to assign to, e.g.: static <T> List<T> listOfAnything() { return (List<T>) new ArrayList(); } Which can be used like this: List<String> stringList = listOfAnything(); Or by letting the compiler infer the type from the return type of a method: List<Integer> listOfInts() { return listOfAnything(); } This is not just some esoteric feature... it's quite commonly used by, for example, deserialization libraries and functional programming.
- lmz 3y agoThose are all the same underneath. Perl's scalar / array duality is a bit more of a difference.
- xupybd 3y agoGenerics are awesome. They allow you to do partial typing. You don't specify the exact type but you constrain the output type based on the input type. So you have functions that can operate on many types but still have strong typing. Wantarray is not a generic implementation. It's closer to reflection. You can detect the type of variable the caller is putting your functions result in. Then you can branch your program based on the variable type that the caller wants. I guess this is similar to type inference but not exactly as it's not part of the type system. For example, if they want an array return the amounts of each transaction in an array if not return the sum of the transaction amounts.
- cesarb 3y agoThat trick "works" in Java because, for compatibility reasons (Java didn't have generics originally), the generic type is erased by the compiler. Your example compiles to: static List listOfAnything() { return (List) new ArrayList(); } List stringList = listOfAnything(); List listOfInts() { return listOfAnything(); } The generic type isn't monomorphised or even reified; within your method, you don't have access to the generic type T "passed" by the caller. If you need it, you have to pass it explicitly, as commonly used by deserialization libraries: static <T> T deserialize(String input, Class<T> cls) { ... } Which can be used like this: MyStruct result = deserialize(input, MyStruct.class); Note that the deserialization library has no way of knowing the type of the variable the caller is putting the result in, the caller had to pass it explicitly. This is because what the Java compiler actually generated from the code above was something like: static Object deserialize(String input, Class cls) { ... } MyStruct result = (MyStruct) deserialize(input, MyStruct.class);
- dotancohen 3y ago*nix applications also can alter thier output based on where it's going, e.g. to a pipe or to a file.
- xupybd 3y agoThat's actually a good point. It seems to work well in that context. I'm not sure I have an entirely rational reason for liking it in one context and not the other.
- actionfromafar 3y agoI don't like it! :-D Of course, now I expect it so don't get bitten anymore.
- G3rn0ti 3y ago> I remember the tedium of having to maintain your own stacktrace With Carp::confess you get the stack trace easily when throwing an exception. It's been a core module for ages. Of course, Perl lacks a flexible condition system like Common Lisp. So all you got is an exception object you can try to handle but no restart handlers you can use to go back down the stack trace. But that's a common limitation of almost all languages supporting exceptions natively.
- wink 3y agoPHP's string datatype (in the C code) had a length field in addition to the actual bytes (probably still has), so the idea is not always bad (if most of what you do is string manipulation, so len() is O(1) and not O(n)) but I get your point, that's hidden deep in the language for perf reasons, not in user code :P
- forgetfulness 3y agoNo, that's fine, this is more like the `len()` function being called implicitly if the array is being passed to where a "scalar" value is expected. Like here: sub some_function($) { my $some_var = @_; print("$some_var\n"); } my @arr = (1, 2, 4, 7); some_function(@arr); This prints the length of the array.
- katzgrau 3y agoI worked at Yahoo, and it was Perl and PHP. Sheer madness. Their were some talented folks but I'd like them more to cowboys - git'r done instead disciplined engineers. Lots of production applications that had the code quality of your typical hacky side project. I once had a debate with my manager about classes/OOP in PHP5. He didn't like it because it usually meant having separate files and includes per class, and he likes to have all code for a PHP page in a single pane in Vim. "But Kenny it's all in one file, everything I need to work on is right here!" I still laugh about that.
- latchkey 3y ago> Lots of production applications that had the code quality of your typical hacky side project. We laugh about it now, but that's why we end up with things like this: https://www.nytimes.com/2017/10/03/technology/yahoo-hack-3-billion-users.html https://www.nytimes.com/2017/10/03/technology/yahoo-hack-3-b...