Giter VIP home page Giter VIP logo

here-be-dragons's Introduction

Deprecated

This project is no longer maintained. No new issues or pull requests will be accepted. You can still use the source or fork the project to suit your needs.

Here Be Dragons

Here be dragons is an Intellij/Android Studio plugin that let's you annotate your impure Java methods with the @SideEffect annotation and shows a little dragon icon in the gutter when you call them.

How the plugin works

Why would I want to do this?

When writing functional style code, isolating impure and pure functions becomes very important. This helps you visually identify which methods are impure when a bunch of methods are being called in a code block.

For a beginner friendly introduction to functional programming in Android, please checkout out my blog series.

Installation

Install the plugin

Download the plugin jar and select "Install Plugin From Disk" in IntelliJ's plugin preferences.

Add the annotation library

Add the jcenter repository to your gradle build file if it's not already present:

repositories {
    jcenter()
}

Next, add the lib containing the @SideEffect annotation as a dependency:

dependencies {
    compile 'com.anupcowkur:here-be-dragons-annotation:1.0.1'
}

Usage

Simpy add the @SideEffect annotation to any method you want like this:

import com.anupcowkur.herebedragons.SideEffect;

public class Test {
    @SideEffect
    public void foo() {
        // do some impure things
    }
}

And when you call the method anywhere, you'll see the dragon icon show up in the IDE gutter.

License

This project is licensed under the MIT License

here-be-dragons's People

Contributors

anupcowkur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

here-be-dragons's Issues

Watch for global variable mutation

Would it be possible to detect side effects in addition to the annotation? Watching for interaction with anything with a greater scope than the method (such as a field). I would be much more likely to use this if I didn't have to remember to add the annotation to every method with a side effect.

Cannot build with java 1.7

My main android module build file have set java version = 1.7

  compileOptions {
    encoding "UTF-8"
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
  }

Here is the error message when ran the app.

Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add 
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
...while parsing com/anupcowkur/herebedragons/SideEffect.class

Very minor typo in ReadMe

In this line

This helsp you visually identify which methods are impure when a bunch of methods are being called in a code block

It should be helps.

Please correct it.

.

Annotations for indicating a parameter is modified by the function

Let me start by saying, the name you've come up with for this library is awesome, I'm very tempted to steal it to make my own variation.
That being said, I figured I'd run my proposal by you before performing grand theft (please understand this is meant as a compliment, not a threat).

I'd like to be able to annotate the parameters on methods if the parameters get side effected.
For example:

/**
 * Allow us to annotate that collection passed has elements added/removed/sorted/ect...
 * within the method.
 */
int doActions(@SideEffectModifies(type = COLLECTION) final Set<Something> somethings) {
    somethings.add(anotherSomething());
    return somethings.size();
}
/**
 * Allow us to annotate that collection elements get modified when passed to the method.
 */
int doActions(@SideEffectModifies(type = ELEMENTS) final Set<Something> somethings) {
    something.forEach(something -> something.setIt("it"));
    return somethings.size();
}
/**
 * Allow us to annotate that both kinds of side effecting happens.
 */
int doActions(@SideEffectModifies(type = BOTH) final Set<Something> somethings) {
    somethings.add(anotherSomething());
    something.forEach(something -> something.setIt("it"));
    return somethings.size();
}

My particular use case is that I'm refactoring a large swath of code. I'd like myself and other developers to leave hints to each other that we have discovered this kind of side effecting behaviour. The goal is, while you might not be able to do the refactor to fix the problem at the time, you've figured out this is what is going on.

Provide Kotlin support

This is a neat little plugin, I can see it come in very helpful. I mainly develop in Kotlin though, so it would be great if I could also use it there - right now, I can annotate Kotlin code and it will show the dragon when called from Java code, but no dragons are shown in Kotlin code.

Ability to mark all methods inside a type with SideEffect

For instance, all methods in a Retrofit interface instance carry side-effects. Instead of marking every single method with a @SideEffect (which also clutters the method definitions in the class), I prefer marking the entire type instead.

This would also require another annotation to mark exclusions inside a class. Maybe another annotation named @Pure.

Take advantage of the Releases mechanism on GitHub

If one creates a tag of each release, from that point forward GitHub provides a way of attaching arbitrary release artifacts to that tag, moving the burden of hosting the artifacts onto GitHub and out of the repo itself.

One may do that manually, or GitHub also offers an API to create a release and then upload assets into it. One can create an api key suitable for housing in Travis or Circle or whatever, but the scope needs to be repo as I don't believe there is a scope specifically to "create a release."

GitHub also has helpful content which describes the overall picture

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.