Thanks for the suggested methods (@code_warntype and lint). I had 
experience with lint in Python and I liked it.

My original question may be misleading - I didn't mean to infer the Julia 
compiler may cause type mismatch problem whether type conversion is 
involved or not. What I meant is the programmer may have made a mistake in 
the source code that could lead to a type mismatch. Such mistakes would be 
caught by the compiler in traditional static-typed languages like C++, C# 
and Java - these are actually very common bugs. I just wonder if there is a 
best-effort way to flag some of these in Julia before running the code, 
given that the programmer is willing to put in extra effort to annotated 
the type of variables involved. 

Or, going further along this line, maybe such a feature is desirable: a 
programmer can do fast prototyping benefiting from the dynamic typing; but 
when one needs to go production, at the flip of a switch one can reinforce 
static typing (type inference like what Scala does is still OK though), and 
type mismatches are thus all flagged before execution, even if that means 
one has to go back and annotate or declare all variables as a "tidying up" 
before production.

I have no idea if this kind of feature is even reasonable / feasible to ask 
from Julia. What I mean is, I do see use cases in daily work as an 
electrical engineer who also writes a lot of code that is subject to no 
rigorous software engineering rules, is far from being 100% covered by 
tests, but could be used regularly by internal users including myself. I 
wish for fast prototyping of one-off tasks or rapid try-and-error; but when 
I need to get more serious I also wish a compiler or code analysis tool can 
help catch as many dumb mistakes as possible early on in largely the same 
source code I prototyped, not at run time.

Thanks,
-Zhong




On Tuesday, July 12, 2016 at 6:09:36 PM UTC-5, Zhong Pan wrote:
>
> One big problem of dynamically typed languages is type mismatch errors 
> only pop up at run time. When I say "type mismatch" I refer to the case 
> when the compiler/interpreter cannot reasonably guess a conversion, 
> therefore e.g. assigning an integer value to a double variable does not 
> count.
>
> It'll be nice to allow quick coding leaving out type annotations for fast 
> prototyping; later on to reach production, the programmer can improve 
> reliability and reduce run-time errors by annotating types as much as 
> possible.
>
> Is there an option or separate tool that can perform a best-effort type 
> check on the source code *before *it starts running? I heard that type 
> mismatch may be caught by JIT compiler early if all parameters of a 
> function have been type annotated; however JIT compilation happens at run 
> time in user's perspective. I think it's desirable to be able to catch 
> problems even before running anything. And the option / tool does not (and 
> will not be able to) catch all type mismatch problems; but it should be 
> able to flag clear violations.
>
> Thanks,
> -Zhong
>
>

Reply via email to