in reply to Re: Benefits of everything is an object? Or new sigils?
in thread Benefits of everything is an object? Or new sigils?
Unfortunately I can't spend as much time to reply here like I did for other posts in this thread.
> That's why I spend so much time sketching data structures on paper before I touch the keyboard.
So do I, but sometimes its better to just start to code with the intention to prototype the real thing. And even in prototyping the Javascript approach is less painful than Perl.
> I would also argue that one ought not use blessed array refs as objects.
I disagree, maybe I'm too influenced by Conways OOP book but I see Perls possibility to bless any ref as the advantage of this (maybe too?) flexible OO System.
After tieing the array to a new class, push() will act however you want it to act, e.g. the data can be easily inside out. I can't see why a blessed arr_ref should act differently to a blessed hash_ref, so no need to worry about ugly side effects.
> But I have a difficult time with a plural object.
IMHO this "plural naming convention" is a workaround for missing sigils. Actually I spend too much time to invent clear plural names where I would prefer to simply set a sigil.
Normally I have my own hungarian notation writing something like $A_employees or $employees_ar to denote the nature of the variable. Contrary to PBP I prefer the former, because I want to know what I'm dealing with at one glance and _one_ end of the word , not on both ends. And Perl favors the beginning...
> I expect the sigils only to tell me what will happen; not what the author's intent may have been. For the latter (since I'm not that good), I'll read the comments.
I agree to a certain point, the sigils should be very clear about context and data type.
I think mentioning Perl 6 was misleading...I'm also not happy about hash-slices which start with a $! :(
In my vision these sigils should only be in scalars context, such that €employees == $employees is always true.
The differences I'm meditating of are
push €employees, "elem" is possible
<UPDATE> Allow me to give an example from another language ... (won't name it here ;-)
>>> a=[1,2,3] >>> len(a) 3 >>> a.__len__() 3
(Here Guido punishes the use of a method (!) by appending 4 extra underscores. We don't need that ... :) </UPDATE>
Such that @{€employees->[$idx_phonenumbers]}[0..1] is the sliced list of the first 2 phonenumbers.¹ ²
Please note, the use of the euro symbol is of course a matter of debate, actually there are some currency symbols ( like $ ) available in Latin 1 AND Western Keyboards, like £, ¢, ¥ and ¤ (the latter is often mapped to €). 4 new symbols should be enough to cover the known ref types: arr_ref, hash_ref, code_ref and scalar_ref.
(I'm not sure if there is a need for a symbol for blessed refs...)
All of what I sketched here should of course be voluntarily activated with something like use refsigils
Cheers Rolf
¹) this is a contrived example, I know that a hash with key "phonenumbers" is a better choice than using an array with an index $idx_phonenumbers! :)
²) there's another possibility to be mentioned, IIRC Perl 6 allows a slice to be called with "method syntax" ->@[LIST] (of course in Perl6 with a point and not an arrow ;)
|
|---|