Annotations (via comments)

About Monkey 2 Forums Monkey 2 Development Annotations (via comments)

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by  nerobot 1 year, 6 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #11197

    nerobot
    Participant

    Using Java I often (or even always) try to annotate methods and params with at least @Nullable and @NonNul :

    It helps to reduce possible NullPointerException. For apps it’s super-useful.

    Don’t know would it be in monkey or not.

    But today I read about JSDocs: we specify var type in docs to make checks by these types at function calls etc.

    For monkey:

    IDE can read annotations from @param and @return and notify about potencial problems.

    Real annotations are better but more expensive to implement.

    Just a thoughts. What anybody think about that?

    #11230

    Mark Sibly
    Keymaster

    Never really used annotations, are they a bit like compiler warnings in c/c++? I have never been a huge fan of warnings in c/c++.

    I have seen @override used in java I think. Why is it optional? Because it would break too much existing code? What does it actually do then?

    And why not add @nulable as a language keyword?

    As you may have guessed, I’m not really into just throwing every possible construct at the language (simple as possible, no simpler etc)  ala c#, and it’d be nice to have some ‘examples’ of why this is useful too?

    #11244

    nerobot
    Participant

    Never really used annotations, are they a bit like compiler warnings in c/c++? I have never been a huge fan of warnings in c/c++.

    There are annotation processors for processing annotation – we can add our processers for our custom annotation.

    Processors are based on reflection and can inspect our annotated code parts – and generate new code if necessary.

    Result compilation start after preprocessing to compile all that stuff.

    Huge article for Java: http://hannesdorfmann.com/annotation-processing/annotationprocessing101

    I have seen @override used in java I think. Why is it optional? Because it would break too much existing code? What does it actually do then?

    It’s a helper annotation which check “have superclass/interface this annotated member or not”.

    If you remove some methods from interface

    • w/o @override – removed methods stay as a own class methods, stopped overriding and don’t accessible via interface, but you have no notified about any problems here
    • with @override – compiler stopped and say “you have no such interface method”, so you don’t break your expected logic.

    And why not add @nulable as a language keyword?

    There are many other annotation which processed the same way, so is better to use Processors and don’t clutter the language itself.

    Annotations can have params – therefore they have more power than keywords.

    As you may have guessed, I’m not really into just throwing every possible consteuct at the language (simple as possible, no simpler etc) ala c#, and it’d be nice to have some ‘examples’ of why this is useful too?

    I agree with that.

    Main barrier here is how to processing annotations in monkey – processors should be usual monkey classes, I don’t know is it possible to run them and pass all annotated items..

    There are can be json’s annotations as a real example:

    @JsonName("personName") – allow us rename variable name and always have it as personName – don’t break deserialize process.

    @JsonIgnore allow to skip any fields by serializer

     

    All this stuff is looks hard to implement and have a phantom benefit, at least this time. 🙂

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.