I find static typing to be most effective when working with code that I
didn't write or that has many dependencies.

Once familiarized with the error syntax, it can be faster than consulting
the documentation to understand what the expected inputs and outputs of a
function are, especially with decent intellisense

It can also be faster to refactor code by failing fast at compile time
instead of run time. Of course, a comprehensive test suite can provide an
even higher level of security when refactoring, but that is not always
afforded

Some common examples I encounter:

1. Refactor a method call from having a handful of parameters to accepting
a type instead. One 'safe' approach may be to create a new overload for the
function, but maybe it makes sense to clean up all the existing references.
The compiler can find the references faster than I can

2. Remove a method / parameter that's no longer in use. Add a parameter
(although many languages offer a default parameter syntax for unspecified
parameters -- c# recently)

I haven't felt the benefit as often when using a small code base written by
me.  Specifically in J, I find myself writing small verbs that accept 1
parameter or two at max. I don't consider a single parameter that is a list
of parameters as a single parameter either ( 3 : ' ''a b c''=.y ') would
count as 3 parameters to me. As a result, I don't find as much complexity
that the type systems seem to be designed to deal with.

When dealing with larger code bases, I appreciate type systems that stay
out of your way and seem to figure out the right thing to do. C# does a
nice job of this with type inference and even dynamic/duck types. My larger
Javascript projects can start to become unwieldy which has me starting to
look towards typescript with optional typing.

A few common examples that drive me crazy:

Dynamic typing (javascript) - math:

3+0.001+1
4.0009999999999994

Static typing (c#) - requiring casting:

//this is ok
decimal x=3;

//this throws a compile time error: Operator '*' cannot be applied to
operands of type 'decimal' and 'double'
decimal y=x* 1.5;

//this is ok -- needed to add the m
decimal y=x * 1.5m




On Thu, Apr 2, 2015 at 10:05 PM, Devon McCormick <[email protected]> wrote:

> I'm interested in examples demonstrating the value of static typing.  Do
> you have any you find particularly compelling?
>
> On Thu, Apr 2, 2015 at 8:01 PM, Aistis Raulinaitis <[email protected]>
> wrote:
>
> > Definitely. Thanks. I felt a little sad for the author's distaste for
> > static typing. As a Haskeller I actually see static typing as tool to
> lean
> > into when things get tough, instead of a thing you have to work against.
> To
> > me programs are just data and mappings of that data from input to
> output. I
> > may just be one of those weirdos, but for me (at least right now) the
> > perfect language for me would be if J and Idris/Agda had a baby and made
> a
> > dependently typed array language. ...and regained back APL's symbolic
> > syntax and left ASCII in the dust.
> > On Apr 2, 2015 4:33 PM, "Joey K Tuttle" <[email protected]> wrote:
> >
> > > With this interesting article -
> > >
> > > http://www.technologyreview.com/review/536356/toolkits-for-the-mind/
> > >
> > >
> > > ----------------------------------------------------------------------
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> > >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
>
>
>
> --
> Devon McCormick, CFA
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to