Smart Compiler

For questions and postings not covered by the other forums
User avatar
Stokes
Posts: 50
Joined: Wed Oct 13, 2010 2:06 pm
Location: QLD, Australia

Smart Compiler

Postby Stokes » Fri May 13, 2011 11:24 am

This has probably been discussed before but I can't find any information about it.

When you compile a method in Jade it will tell you if there are any errors in the Syntax.

What would be good is if Jade could warn you about any areas of the method that could be improved. Maybe it would tell you:

- If there are any unused local variables.
- If there are any transients being created but not deleted
- If you are putting in app. within an application class
- If you have a local variable named the same as a class variable

I'm sure there are many others that could be implemented but I can't think at the moment.

None of these would cause compile errors but would improve performance and any potential problems if they are sorted out. I was talking to a colleague who has developed in a lot of other languages and he mentioned that would be 1 thing that Jade does not do where the others have a compiler that will give you warnings.

Maybe you can continue using F8 as per normal but maybe use F9 for a smart compile that may take a wee bit longer.

murray
Posts: 140
Joined: Fri Aug 14, 2009 6:58 pm
Location: New Plymouth, New Zealand

Re: Smart Compiler

Postby murray » Fri May 13, 2011 1:08 pm

I always automatically do Alt-M, V to check for unused variables.

Transients being created and not deleted is a runtime issue, dependent on design. You can't expect the compiler to guess correctly.
Whether you use explicit or implicit app reference is a deleveloper choice, not necessarily an error or warning.
What about eliminating all those unnecessary "self." references? ;)

Perhaps you could write a JadeScript to parse your own methods for such things that you personally want to catch?
If you search these forums you will find that some others have created their own source code parsing solutions (Allistar, I think).
Murray (N.Z.)

User avatar
Stokes
Posts: 50
Joined: Wed Oct 13, 2010 2:06 pm
Location: QLD, Australia

Re: Smart Compiler

Postby Stokes » Fri May 13, 2011 1:57 pm

Yes I check unused variables by right clicking on the method. But it would be an improvement if Jade could warn you without you having to check when you compiled the method.

With regards to the transients being deleted, I don't expect Jade to guess correctly whether they should be deleted within the method or not. But if it was included as a warning then the developer could decide whether to ignore it or not.

I don't know why a developer would want to use app. within an application method when there is no need to do it and it makes your application slower. The same goes for self. however I have not done any speed tests for that so I couldn't tell you if removing self. would speed up your application. But that would be another thing a smart compiler could do.

Thanks for letting me know someone else has done this. I will try to find thread.

murray
Posts: 140
Joined: Fri Aug 14, 2009 6:58 pm
Location: New Plymouth, New Zealand

Re: Smart Compiler

Postby murray » Fri May 13, 2011 2:50 pm

You can write a JadeScript to parse method source code. The following methods may help to get you started...
Schema.getAllClasses()
Schema.getLocalClass()
Class.getMethods()
Method.getSource()
Murray (N.Z.)

User avatar
Dr Danyo
Posts: 56
Joined: Fri Aug 21, 2009 8:59 am

Re: Smart Compiler

Postby Dr Danyo » Sat May 14, 2011 5:47 am

I like the idea of automatically checking for unused variables.

Here is my attempt at an auto hot key script that will check for them on every F8 Compile

#ifWinActive JADE
F8::
{
Send, {F8}
Send, !m
Send, {v}
SetTitleMatchMode 2
SetControlDelay -1
WinWait, Unused Local Variables,,2
ControlClick, ,Unused Local Variables,,,, NA
}

User avatar
BeeJay
Posts: 266
Joined: Tue Jun 30, 2009 2:42 pm
Location: Christchurch, NZ

Re: Smart Compiler

Postby BeeJay » Wed May 18, 2011 10:56 pm

Personally I like the fact that the Jade compiler only reports compile errors versus other compilers that try to get too smart and provide tons of warnings that developers often ignore.

This type of static analysis is often better performed by tools targeted to match the specific coding standards of your team, rather than trying to make a generic tool as part of the compiler that won't suit the coding standards of all the different development teams that use JADE. Such compiler warnings would never advise of RootSchema methods or coding constructs that may be "banned" by a given development team. For example, in our team we have our own reimplementation of "setFocus" that needs to be used instead of the standard RootSchema setFocus methods. We also insist on using our version of beginTransaction/commitTransaction/abortTransaction, that take care of additional things such as sending or deleting queued notifications from our notifications manager. None of these would be picked up by compiler warnings, and yet they are more important to us than finding potentially undeleted transients or unused local variables. However, these situations will be picked up by a static analyzer, that can also look for potentially undeleted transients, unused local variables and parameters, etc.

Cheers,
BeeJay.

User avatar
ghosttie
Posts: 164
Joined: Sat Aug 15, 2009 1:25 am
Location: Atlanta, GA, USA
Contact:

Re: Smart Compiler

Postby ghosttie » Thu May 19, 2011 1:12 am

I submitted something similar as an NFS (#36969) a few years ago, but it was rejected.

It would be nice if the JadeMetadataAnalyzer framework was called by the compiler in the main dev environment to enforce policies.

Different companies will have different coding standards and policies e.g. beginTransaction can only be called in methods on the TransactionAgent class (or only in the ModelSchema), or transient objects can only be created in a certain method (for transient leak detection) etc.

Using JadeMetadataAnalyzer they could add custom checks to the standard compiler to enforcing their policies. First of all the normal compiler checks would be performed, and if the method compiled successfully then it would be checked for policy conformance. If the method failed policy conformance, the message returned by the JadeMetadataAnalyzer framework would be displayed and the offending token highlighted as usual when compiling (and the method would be marked as not compiled so it cannot be executed until it conforms). If the method passed policy conformance, it would be marked as compiled and would be allowed to execute. This way there is no run-time overhead, only compile-time.

It is possible that it would only be necessary to do policy conformance checks when compiling in the development environment. If this is the case, then the addition of policy conformance checks would not affect schema load times on client sites.

If a policy changed, all methods in user schemas may need to be recompiled to ensure their conformance.
I have a catapult. Give me all the money or I will fling an enormous rock at your head.

torrie
Posts: 92
Joined: Fri Aug 14, 2009 11:24 am

Re: Smart Compiler

Postby torrie » Thu May 19, 2011 11:28 am

There's another thread on this viewtopic.php?f=7&t=82&hilit=Warnings

I'd add my vote for some warnings. There's a number of potential problems (using an object variable before it's been assigned to, not setting return values in all execution paths etc) that the compiler could detect. Having potential issues detected at compile time would be an advantage as resolving isues like 1090 exceptions during compiling would be much more efficient that resolving these during testing or deployment.

When I used to code in C I usually turned on all the warnings. There will be times were you want to do things that would raise a warning (e.g. an assignment inside an if statement for example.) C provides some macros that the compiler reads which allow specific warnings to be turned off for a block of code. This prevented the warnings from being raised, but also made other developers aware that you realised that you were breaking the conventions and (hopefully) knew what you were doing.

User avatar
andy-b
Posts: 24
Joined: Mon Jul 05, 2010 2:00 pm
Location: Dunedin, NZ

Re: Smart Compiler

Postby andy-b » Thu May 19, 2011 11:58 am

right-click on method for Unused Local Variables


Never noticed that item before, might come in handy :D

User avatar
Stokes
Posts: 50
Joined: Wed Oct 13, 2010 2:06 pm
Location: QLD, Australia

Re: Smart Compiler

Postby Stokes » Fri May 20, 2011 8:32 am

One of the best things about this warning system would be for anyone trying to learn Jade. It would improve the coding for any developer and save time i.e. trying to find memory leaks,

This is the response I got from Jade:

"....while some may have some merit it is unlikely that they would be implemented. If you wish, you may resubmit the feature request at a later date for further consideration."

When I asked why it would not be considered at this time:

"A new feature suggestion is implemented according to the evaluation of a number of factors including but not limited to
1) The benefit the feature provides
2) The amount of demand for the feature (Sometimes new features are paid for where a client particularly desires that feature).

Because it is unlikely that the feature suggested here will be implemented, it is preferable to close the contact (for one thing, the number of new features suggestions can grow unwieldy and make it difficult to evaluate which features to implement in a new release)."

So if the demand for this feature is high then Jade might develop it. Vote now!


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests

cron