7 ms·
If it's so important to decorate variables with unique punctuation to visually distinguish between two particular kinds of many possible types, then why don't y
by DonHopkins 11y ago
If it's so important to decorate variables with unique punctuation to visually distinguish between two particular kinds of many possible types, then why don't you also decorate function calls according to whether they return lists or scalars?
How should you decorate functions that return different types depending on what context they're used in? http://perlmaven.com/wantarray http://perlmaven.com/wantarray
If it's so important to visually distinguish the names of scalars and arrays, then shouldn't you also be able to distinguish a string from an int, like BASIC's a$ -vs- i%?
So why just distinguish lists and scalars? Why not go all the way to Hungarian Punctuation and use Unicode and Emoji characters to uniquely decorate variables for every other possible built-in and user defined type?
https://en.wikipedia.org/wiki/Hungarian_notation#Relation_to_sigils https://en.wikipedia.org/wiki/Hungarian_notation#Relation_to...
- hahainternet 11y agoYou might be a little confused, I'm pretty sure that wantarray and the concept of functions caring about context is entirely gone in Perl 6. Now you are expected to return objects which 'do the right thing'. However, if you really want to do some of the other things you've listed they are possible to do. Perl 6's syntax can be augmented by the programs being executed. I'm honestly interested though, was I ultimately wrong above? Is there a smart way to define a function in python that can take both a single item and a list of items? In Perl 6 I'd just define a multi sub where the list form applies the single item sub for each item in the list.
- DonHopkins 11y agoIt might be gone from Perl 6, but the idea of dividing all possible types into two different classes, and then using punctuation to distinguish variables holding those two classes, is from Perl 5, just like the idea of functions caring about the context of their return value. If Perl 6 is an entirely new language, then why is it riddled with so many bad ideas from another language that only coincidentally shares the first 4 alphabetic characters of its name? Why the artificial scalar/array dichotomy? What is it that is so important about being able to distinguish variables holding scalar-like values and array-like values by punctuation, but it doesn't matter that you can't distinguish variables holding strings and integers by their punctuation? And how can you be consistent about types that act like both scalars and arrays, like strings? Or user defined types that might behave like scalars or arrays but are represented by objects? Are those treated as arrays? Or are they references, treated as scalars? Scalar -vs- array is a false dichotomy that's deeply and unnecessarily embedded in the very syntax of the language.
- hahainternet 11y agoI'm not entirely sure you've illustrated that it's a bad idea. I believe that I illustrated that a simple pattern is not easily doable in Python but is in Perl 6. You'll have to show that this is a bad pattern or the implementation is bad or something at least to prove your point. There's more to sigils than just scalars and arrays too, as you can see here: http://doc.perl6.org/language/variables#Sigils http://doc.perl6.org/language/variables#Sigils The difference in your examples are that scalars describe more the 'shape' of the variable than its type. Given that a lot of programming is dealing with lists or 'dictionaries' this is a fairly minimal intrusion into the code that very much improves succinctness, correctness and the ability to easily read what some code is doing. Oh, and strings don't act like arrays in Perl 6 AFAIK. Because they could be split on characters, or codepoints, or bytes, you must be explicit: > for "Hello".comb -> $c { say "Character $c" } Character H Character e Character l Character l Character o (Or to be perly) > .say for "Hello".comb
- DonHopkins 11y agoWhat's wrong with using "isinstance(lst, str)" when necessary? The few cases when you need to make that distinction aren't worth infecting the rest of the code with punctuation marks. Using letters to explicitly spell out self-documenting words in the few function names that need to make that distinction is much less intrusive, more flexible, unambiguous and capable of precisely distinguishing many more nuances, than using a small set of punctuation characters throughout all of your code to mitigate rare problems with just a few cases. Of course it can be taken to an extreme, but it's much easier to guess or google for the meaning of an Objective C selector than for a bunch of Perl punctuation. http://stackoverflow.com/questions/15152171/what-is-the-longest-method-name-you-have-seen-in-ios-cocoa-touch http://stackoverflow.com/questions/15152171/what-is-the-long...
- hahainternet 11y ago> What's wrong with using "isinstance(lst, str)" when necessary? In order for it to be like the Perl6 implementation I would have to check against every type of iterable AFAIK. For example, a generator would be perfectly acceptable, but is there a unique function I could check with hasattr? Clearly you feel that sigils are intrusive in Perl 6, but having written a bunch I find it quite enjoyable, and they're pretty easy to find in the documentation too. Ultimately, you can use variables without sigils, but with caveats: http://doc.perl6.org/language/variables#Sigilless_variables http://doc.perl6.org/language/variables#Sigilless_variables
- muraiki 11y agoI downvoted you, but perhaps too hastily. I think that sigils are a matter of opinion, and there are benefits to using them and also to not using them. I think that this downvote was really intended for your original comment, which I interpreted as essentially stating a personal preference as fact.