Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bear to validate functions #2354

Open
kriti21 opened this issue Mar 17, 2018 · 13 comments
Open

Add bear to validate functions #2354

kriti21 opened this issue Mar 17, 2018 · 13 comments

Comments

@kriti21
Copy link
Contributor

kriti21 commented Mar 17, 2018

A generic bear that would check if the functions in a program file are of some reasonable length and solve one specific purpose. It would suggest if a long function can be split into two or more smaller ones.

Tags: bear-proposal, generic-bears

@gitmate-bot
Copy link
Collaborator

GitMate.io thinks possibly related issues are #247 (Add PMDBear), #1638 (Add nginxBear), #2297 (Add vale lint bear), #101 (Bear for vala), and #2150 (Add pylamaBear).

@Makman2
Copy link
Member

Makman2 commented Mar 17, 2018

That sounds awesome, but also pretty hard :D Maybe we can somehow detect such code parts with code-complexity analysis?

@kriti21
Copy link
Contributor Author

kriti21 commented Mar 17, 2018

I am glad you liked the idea @Makman2 I will do some research on its implementation and get back to you. :)
Also can you suggest a name for this bear? How does ValidateFunctionBear sounds? And please assign this to me.

@Makman2
Copy link
Member

Makman2 commented Mar 17, 2018

ValidateFunctionBear sounds too vague, but don't have a good idea now either. But naming is something that we can consider once we have a technical concept :)

@kriti21
Copy link
Contributor Author

kriti21 commented Mar 19, 2018

@Makman2 @jayvdb Here are some parameter based on which we could judge the complexity of any function:

  • Number of lines (Differs according to languages, can be included in the settings)
  • Number of loops (3 max and then no nested loop)
  • Number of nested loops (1 max and then no simple loop)
  • Not more than one level of indentation
  • Number of input parameters (ideally not more than 5 but 8 can be allowed)
  • Number of return values (differs with language for eg. In c++ only one value can be returned or an array can be modified, In python, ideally not more that two different values should be returned or a tuple should be used instead)

By considering these factors and maybe assigning different weights/measure of severity to each one of these, we can identify complex functions and suggest splitting.
What do you think?
Any suggestions for improvement? This is part of my GSoC proposal.

@jayvdb
Copy link
Member

jayvdb commented Mar 19, 2018

which languages are you considering targeting with this bear?

C/C++/etc should be done based on the Clang bears.

Python, IMO, should wait until the Python AST project is completed.

If you are intending to make it very generic, supporting any language, then the extraction of function metadata in a generic manner is going to be the very hard part, and that should be a project over in the coala core projects' language definitions area.

@aptrishu
Copy link
Member

aptrishu commented Mar 19, 2018

@kriti21 How do you plan to judge if a function is solving a specific task? also, how do you plan to know what actual task function is supposed to do? Can you explain broadly (I'm assuming you plan to solve it generically)? because it seems somewhat infeasible to me without AST or some other complexity.

@kriti21
Copy link
Contributor Author

kriti21 commented Mar 19, 2018

which languages are you considering targeting with this bear?

I was targeting on C++ and Python for now. But in the long run, I would like to be very generic. @jayvdb
Should i drop this idea for GSoC in that case?

@kriti21
Copy link
Contributor Author

kriti21 commented Mar 19, 2018

also, how do you plan to know what actual task function is supposed to do? Can you explain broadly?

I don't think this is possible unless using some really complex methods or tools. Based on #2354 (comment) these parameters though, we could only judge the complexity to some extent. How many tasks a particular function does is really dependent on the code and language used. @aptrishu

@aptrishu
Copy link
Member

Yeah, That is why I thought, it would not be possible as a generic bear. because judging what specific tasks a function is doing is pretty complex.

@jayvdb
Copy link
Member

jayvdb commented Mar 19, 2018

Frankly, Python is too hard. Even C++ is very hard, but thanks to CLangBear you can take advantage of a very good ast on which to build a bear, and it can be generic across a large group of languages.

@palash25
Copy link
Member

@kriti21 first of all cool idea 👍 secondly rather than a bear (which seems impractical as this idea is too big and complex to be implemented as a generic bear) maybe you should focus on building an API for it something like a MethodComplexity API (I think this name would better describe the purpose of this API rather than ValidateFunction). Once the core functionalities of this API are implemented this could be used to to make smaller generic bears that perform some specific complexity analysis.
This would make a cool project imo.

@Makman2
Copy link
Member

Makman2 commented Mar 20, 2018

Yeah let's start with a specific language and then try to develop more generic techniques. As we have Clang stuff like @jayvdb mentioned, we might start there, so we can focus on the actual logic 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

6 participants