Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

I don't like annotation syntax

by Liebranca (Acolyte)
on Jul 13, 2022 at 10:25 UTC ( [id://11145472]=perlmeditation: print w/replies, xml ) Need Help??

Hello,

By 'annotations' I mean 'attributes'. And by 'do not like', 'hate' and 'utter disgust that makes me wish for my own unborn demise' I actually mean it just doesn't click right (hey, that's a way to put it).

And I wonder if anyone actually likes the :annotation(:attribute) syntax because I seldom see it outside of a *certain* OOP proposal that at least to me smells an awful lot like weird C++ fetish roleplay during which someone must've forgotten the safe word.

Alright, hey, listen. I know that's too harsh. But if I want weird octopus dog for dinner, then I'll just have that. A 'class' keyword and all derived farts incumbent on the ever philosophizing theorymongers of objectification, I really do not care for.

So why am I going on about this? I'm writing a preprocessor. It doesn't really introduce new syntax, just fake attributes that are removed before the compiler even gets to see them.

The purpose of these attributes is simple: marking subroutines for inlining and variables as blessed references to one or another package -- just because I need to know where to pull a definition from before I get to inlining anything. It's a pinky-promise, not a typecheck.

But this syntax...

my $eyes :bleed = '<-whenever I see :this and :that';

... is frankly not my cup of tea. But I *do* wonder who likes it, if anyone, and why. I mean, I get it. I'm an outcast, a widower and I'm pissed. To say I'm out of touch is an understatement. So alright, I'm willing to listen to reason. Where is reason?

I can transform an entire file, and therefore am entirely in possession of the arcane power to change the language itself into hexspeak spaghetti; I'd much rather work on something other people can read. Or more like, I'd much rather work on something that doesn't require you to basically relearn the language in order to use it.

It must FEEL like it's still the same thing. That is why I care to do this:

use inline; MyPackage::MySub(); # contents of sub will be inlined no inline; MyPackage::MySub(); # will not be inlined

^because it's what feels more natural, more Perl-esque, far as I'm able to tell. It's the same to perl the binary because the preprocessor in question strips those two use/no lines anyhoo, so they could just be whatever I say. I could just enforce Turbo C on 16-bit Windows rules because that's how I was taught way back when and it makes me feel nostalgic to #include <conio.h> and define functions inside a macro just because I can. Wouldn't that be silly of me?

Yes, it would be silly. Sorry, this is a lot of ranting. I'm trying to think of a better way to make the pinky-promise to the preprocessor that a given variable is a blessed ref that isn't just simply adding the pinky-promise keyword and calling it a day. This is driving me crazy.

If people feel annotations for this are alright then I must defer to their judgement. Mostly because I can't think of anything better that doesn't look like C. And that's that, you know.

Have a good day.

Replies are listed 'Best First'.
Re: I don't like annotation syntax
by LanX (Saint) on Jul 13, 2022 at 12:53 UTC
    There are some use cases of attributes, because it has compile-time effects.

    Mostly meta-programming, like in debugging or macro expansion.

    But the biggest problem is IMHO the implementation of the arguments of an attribute

    In :attribute(args-list) args-list isn't parsed like a Perl list but some kind of string like in qw ... and here are dragons.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      At one point I used an actual code attribute to register subroutines for inlining; the attribute sub itself did some processing of a B::Deparse'd version of the code (gotten with coderef2text or something) and then saved some metadata to a hash. Later on, I'd dump the entire thing to a file on an INIT block.

      I've deprecated that system already for unrelated reasons, but it was pretty nice for a lazy way of automatically gathering stuff from files. I found attributes themselves to be useful most of the time, my gripe is purely syntactical.

      I *am* quite mad ;>
Re: I don't like annotation syntax
by hv (Prior) on Jul 13, 2022 at 11:09 UTC

    If people feel annotations for this are alright then I must defer to their judgement. Mostly because I can't think of anything better that doesn't look like C.

    There is a my Dog $spot syntax that in some sense declares (at approximately pinky-promise level) that $spot will be isa Dog.

    In `perldoc -f my` we see my TYPE VARLIST which is described by:

    The exact semantics and interface of TYPE [is] still evolving. TYPE may be a bareword, a constant declared with + "use constant", or "__PACKAGE__". It is currently bound to the +use of the fields pragma

    I'm not sure what "bound to the use of the fields pragma" is intended to mean, but you probably don't need to care if your preprocessor is in any case going to strip it out.

    (Update: added quote from OP)

      I think that's off topic, it's a type declaration and not an attribute.

      Very different things, type declarations are just stubs and badly documented and I think nothing happened there in the last 20 years.

      > "bound to the use of the fields pragma"

      see fields

      compile-time checking if you use hash keys of a typed Hash/Class.

      also hardly used

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Re: I don't like annotation syntax
by Anonymous Monk on Jul 13, 2022 at 11:02 UTC
    Welcome. Ive never used it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://11145472]
Approved by Fletch
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-19 17:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found