4 ms·
bash is worse than perl. I usually avoid it with python whenever possible.
by secondcoming 4y ago
bash is worse than perl. I usually avoid it with python whenever possible.
- AceJohnny2 4y agoI've hated Perl until I had to write significant Bash code. I still dislike Perl (it has pointers! pointers!), but its syntactic sugar for running shell commands and regexes makes shell-style scripting easier than Python.
- mr_toad 4y agoPerl has symbolic references and hard references (pointers). And if you have symbolic reference to a collection of pointers the syntax gets confusing really fast.
- wruza 4y agoMay I ask what seemingly horrible meaning do you ascribe to “pointers!” here? Perl references reference values like list, hash, scalar just like Python references lists, dicts, tuples, strings or numbers or any values through a hierarchy of these. The only difference is that in Python you can’t have a list/dict itself, only a reference to it. Perl doesn’t “have” references, it has actual container values instead, which are inaccessible in Python. E.g. @mylist is not an “object”, it is literally a collection of values that will splat into a location of its use. `func(@mylist)` will naturally take n arguments, where n == scalar @mylist. (Unless a prototype of func demands a reference.) Or maybe you’re mistaking it for pointer arithmetic?
- AceJohnny2 4y agoLet me get at this Socratically. What's the syntax to pass a hash to a function, and use it there? Syntax for putting a hash inside an array, or vice-versa? How do you get the keys of a hash that's inside an array?
- wruza 4y agoWhat's the syntax to pass a hash to a function, and use it there? func %h; sub func { my %h = @_; Syntax for putting a hash inside an array, or vice-versa? None that I know of. But you can put a hashref into a list and vice versa: push @a, \%h; # or {…}, $hr $h{key} = \@a; # or […], $ar How do you get the keys of a hash that's inside an array? keys %{$a[0]} Your question could also mean keys %{{@a}} though less likely. But my perl fu weakened after years of wandering and I also remember reading that refs became first-class for common operators and functions (including keys), so dereferencing is not mandatory anymore. Not sure if that’s true, could be a dream easily.
- AceJohnny2 4y agofunc %h; sub func { my %h = @_; Note that the above only works if %h is the only parameter to the function, because your solution swallows the entire parameter array. Otherwise you must pass a hashref. In any case, these are examples of my discontent with Perl's syntax, which gets unreasonably complicated for non-trivial datastructures. To be clear, Perl's references, the \@a or \%h with the backslashes, are what I derisively call "pointers", because they introduce the same kind of complexity. It's a problem when you must use different syntaxes to update/refer to a hash, depending on the scope you're using it: $hash{$key} vs $hashref->{$key} The first syntax is if you have direct access to the %hash, such as the scope that created it. The second syntax is whenever you're forced to pass the %hash as a ref, for example because it's one of many parameters to a function. (And the hashref syntax I used is sugar! The basic syntax, demonstrated with the "hash-in-array" example, is worse) It's a problem when you have to "cast" a type, like in `keys %{$a[0]}` (for the audience: where $a[0] refers to a hashref inside an array, which has to be dereferenced via the %{} syntax, to be used as a hash). This is a simple example, but replace $a[0] with a more sophisticated datastructure, and things get exponentially unwieldy. The above make it harder to keep track of data as you're browsing code. In contrast, Python's everything-is-call-by-reference approach means that, whatever the scope, you can refer to something the same way. There never is differing syntax between 'something' and 'a reference to something'.
- AceJohnny2 4y ago