Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))
Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))
Posted Jul 16, 2015 4:19 UTC (Thu) by raiph (guest, #89283)In reply to: An interview with Larry Wall (LinuxVoice) by juliank
Parent article: An interview with Larry Wall (LinuxVoice)
Private
=======
Almost all the Perl 6 code I've seen uses the `!` symbol for private attribute declarations. I've read many Perl 6 coders say they prefer to use it.
But the `!` is optional. One can write as you suggest for the private attribute except missing out the word `private`:
class Foo { has Task @dependencies; # declare a private attribute that's an array of Tasks }
Public
======
A public accessor is a method, not an attribute.
A method is called using `.` syntax. Thus, assuming a public accessor method called `done` has been written for a class `Foo`, one might write code such as `say Foo.new.done` and it'll work.
The typical way to get a public accessor method written is to ask Perl 6 to automatically generate it for you:
class Foo { has Bool $.done; # declare attribute, generate public accessor }
The `.` is there in the declaration to remind one of a method call.
All methods called with `.` are public method calls so I'm not seeing the benefit of using the word 'public'. And dropping the `.` would be a big backward step imo.
So...
=====
Use `.` for declaring both a private attribute and public accessor method.
Then use the same `.` for calling the method -- with associated semantics/performance (run-time method resolution that only the JIT can optimize).
Use `!` (or simply omit the `.`) for declaring a private attribute.
Then use the same `!` (or not) for reading/writing the private attribute -- with associated semantics/performance (compile-time direct attribute access that's inlinable by an AOT optimizer).
---------------------------------------------
> Using ~ for string concatenation ... is weird.
I still recall the first time Larry explained his choice. It looks like a piece of string. If this mnemonic doesn't instantly make you go "ahhh", well, you're weird. :P
---------------------------------------------
> A good language design should take best practices, and not re-invent the wheel everywhere.
Sure. It sounds like we just disagree on what best practices to focus on and when innovation is a good thing.
Posted Jul 16, 2015 17:51 UTC (Thu)
by bronson (subscriber, #4806)
[Link] (14 responses)
~ may look like a string, but it doesn't look like a string concatenator to me. And ~~ definitely doesn't look like a matching operator. But then, it took me a long time to get used to =~.
Posted Jul 17, 2015 18:26 UTC (Fri)
by raiph (guest, #89283)
[Link] (13 responses)
Really? Once again:
has $foo; # declare attribute
has $.foo; # declare attribute and method
Does that really not make sense to you?
Imo, this should be readable and intuitive for most folk who are used to using `.` for method calls. And forgetting my opinions and shoulds, in actuality I've not seen any newcomers talk about getting tripped up by this when learning Perl 6.
> ~~ definitely doesn't look like a matching operator. But then, it took me a long time to get used to =~.
Yeah, I always disliked =~ and I've heard others say the same.
I'm OK with ~~. Given the usual meaning of ~, it does approximately match a matching operator.
Posted Jul 17, 2015 20:24 UTC (Fri)
by sorpigal (guest, #36106)
[Link] (12 responses)
Sigils are a good thing. They make code easier to read (and understand). If you find this isn't true *you're just not using enough of them*.
As for concatenation, ~ makes as little sense as . or and is no harder to type than +. It only seems weird because it's young. If you want weird, try := for an assignment operator! It's ugly, hard to type and makes no sense... to me, because I don't use many languages that require it. All syntax is intuitive given time. Meaning comes from usage, not the other way around.
Posted Jul 17, 2015 20:29 UTC (Fri)
by juliank (guest, #45896)
[Link]
Posted Jul 20, 2015 10:13 UTC (Mon)
by leifbk (guest, #35665)
[Link] (6 responses)
Posted Jul 20, 2015 11:56 UTC (Mon)
by juliank (guest, #45896)
[Link] (5 responses)
I just remember := as a token. I do not try to relate syntax to real world elements. Why would I do that when I can just remember := in a few milliseconds.
Posted Jul 20, 2015 14:44 UTC (Mon)
by Wol (subscriber, #4433)
[Link] (2 responses)
Because you are not him!
You're coming over a bit as "my way is the only way" - the exact opposite of Perl's TMTOWTDI. Be careful - that attitude can get you into trouble.
Most people like GUIs. I hate them. But then, I'm happy to accept that other peoples' brains are wired differently. Expecting everybody to be a clone of yourself won't get you very far.
(Oh - and why is it a good idea to assume a linguist can't design a language? If he's a professional doing it for the pay, I'd be inclined to agree, but if he's an amateur being paid to do what he loves, then ...)
Cheers,
Posted Jul 20, 2015 15:08 UTC (Mon)
by juliank (guest, #45896)
[Link] (1 responses)
I did not mean this in a negative way. I'm just curious that some people do this, and other's don't. I would have never thought about mnemonics, so this is a new and interesting thing for me.
Posted Jul 20, 2015 20:16 UTC (Mon)
by Wol (subscriber, #4433)
[Link]
Anyways, Dick and his undergrad mates did this, and Dick was amazed when one of them would quite happily hold a conversation while doing it. Turns out this guy counted by "seeing" a ticker-tape go by. What he couldn't do was watch a TV program while counting.
Dick, on the other hand (like, I think, most people including me), counted silently in his head and had no trouble watching - then recalling - the TV but there was no way he could hold a conversation while counting.
Different people are most definitely wired differently. And that is now one of the big tensions with "linux" - all these guis, gnome, kde, X even, are all "against the spirit" of Unix. It's a pretty safe bet all the original Unix luminaries were word-smiths, not visual people. I'm not saying that's good or bad, just that it *is*. I know all this emphasis on guis alienates me.
Cheers,
Posted Jul 22, 2015 19:20 UTC (Wed)
by raiph (guest, #89283)
[Link] (1 responses)
If not, why, regarding the "private/public" feature discussed elsewhere, would you not be able to just remember `!` as a token that means private?
Posted Jul 22, 2015 21:17 UTC (Wed)
by mathstuf (subscriber, #69389)
[Link]
Posted Jul 21, 2015 7:31 UTC (Tue)
by jezuch (subscriber, #52988)
[Link] (3 responses)
Oh, to the language designers a couple of decades ago (before C, basically), it made perfect sense. Assignment is definitely *not* the same thing as equality in mathematics. The latter is a declaration of equivalence of two symbolic expressions; the former is an instruction to perform a side effect (in imperative languages). So it makes sense to use a different symbol. Now we're all brainwashed by C so when we see "if (a = b)" something inside us screams "this is a mistake!!!" ;)
Posted Jul 21, 2015 15:48 UTC (Tue)
by dashesy (guest, #74652)
[Link]
Posted Jul 21, 2015 16:34 UTC (Tue)
by sorpigal (guest, #36106)
[Link] (1 responses)
Perhaps it's not clears, so I'll emphasize: I mean this as much for sigils as other syntax choices.
Posted Jul 22, 2015 20:16 UTC (Wed)
by Wol (subscriber, #4433)
[Link]
I = 10
Which gives me "5000" :-) Oh the joys of untyped variables :-)
Cheers,
Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))
Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))
say $foo; # read attribute
say $.foo; # call method
Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))
Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))
Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))
Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))
Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))
Wol
Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))
> Because you are not him!
> You're coming over a bit as "my way is the only way" - the exact opposite of Perl's TMTOWTDI. Be careful - that attitude can get you into trouble.
Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))
Wol
Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))
Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))
Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))
Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))
Now we're all brainwashed by C so when we see "if (a = b)" something inside us screams "this is a mistake!!!" ;)
More like, that "if (a = b)" bug now has its signature engraved in our genome, and the immune system shows symptoms of allergy including twitching in the eyes and fever.
Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))
Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))
I = I : "00"
I = I * 5
PRINT I
Wol