topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 9:20 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: An experiment about static and dynamic type systems  (Read 7161 times)

Armando

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 2,727
    • View Profile
    • Donate to Member
An experiment about static and dynamic type systems
« on: September 09, 2011, 11:38 AM »
Moderately interesting study. Still worth sharing.
This blog article has good comments at the bottom. [Disclaimer : I haven't read the actual study]


Screenshot - 2011-09-09 , 12_28_46.png


f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: An experiment about static and dynamic type systems
« Reply #1 on: September 12, 2011, 07:00 PM »
Haven't had the time to look at this in detail, but the following caught my attention:
One issue is that experimenter, to reduce variables such as familiarity or different IDEs, developed his own language, Purity, in two variants.
Does that mean everybody were stuck with 'dumb' text editors? In that case, the study is pretty useless... some of the really big advantages statically typed languages offer over dynamic ones is all the assistance you get from your development tools, which is extremely hard to implement for dynamic languages.

If you add some decent type inference into the mix (C#, C++2011, Scala, ...) you gain several of the brevity benefits associated with dynamic languages, without the clusterfsck messup potential.
- carpe noctem

Armando

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 2,727
    • View Profile
    • Donate to Member
Re: An experiment about static and dynamic type systems
« Reply #2 on: September 12, 2011, 07:40 PM »
There seems to be a few methodological weirdnesses in this study, which wouldn't surprising as it's often the case with... studies.

However, there might something to explore there : "dynamic languages" for very small projects, statically typed ones for bigger ones. Makes sense... Maybe

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,288
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: An experiment about static and dynamic type systems
« Reply #3 on: September 12, 2011, 11:21 PM »
...some of the really big advantages statically typed languages offer over dynamic ones is all the assistance you get from your development tools, which is extremely hard to implement for dynamic languages.

+1

C# allows dynamic typing, but I'll be damned if I'll use it if I can at all avoid it. (dynamic and var)

It has its place, but those situations are kind of specific.


I would also be interested to know about how they compare in large scale projects.

Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: An experiment about static and dynamic type systems
« Reply #4 on: September 13, 2011, 01:54 PM »
C# allows dynamic typing, but I'll be damned if I'll use it if I can at all avoid it. (dynamic and var)
'var' is not dynamic typing, it's used for static type inference which is super useful for DRY reasons.

'dynamic' is something to be very careful about - it tends to ripple out if you start using it.
- carpe noctem

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,288
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: An experiment about static and dynamic type systems
« Reply #5 on: September 13, 2011, 05:50 PM »
C# allows dynamic typing, but I'll be damned if I'll use it if I can at all avoid it. (dynamic and var)
'var' is not dynamic typing, it's used for static type inference which is super useful for DRY reasons.

'dynamic' is something to be very careful about - it tends to ripple out if you start using it.

I stand corrected. :)

But close enough. When you look at it, var looks like a dynamic type. e.g. var acme = "Rocket Skates"; vs. var acyou = 500;

http://msdn.microsof...ibrary/bb383973.aspx

Beginning in Visual C# 3.0, variables that are declared at method scope can have an implicit type var. An implicitly typed local variable is strongly typed just as if you had declared the type yourself, but the compiler determines the type. The following two declarations of i are functionally equivalent:

http://msdn.microsof...ibrary/bb384061.aspx

Local variables can be given an inferred "type" of var instead of an explicit type. The var keyword instructs the compiler to infer the type of the variable from the expression on the right side of the initialization statement. The inferred type may be a built-in type, an anonymous type, a user-defined type, or a type defined in the .NET Framework class library.

However, this:

Code: C# [Select]
  1. var a = 1;
  2. var b = "123";
  3. var c = a + b;
  4. MessageBox.Show(c.ToString());

Outputs:

1123

And

Code: C# [Select]
  1. var a = 1;
  2. var d = a + 2;
  3. var b = "123";
  4. var c = d + b;
  5. MessageBox.Show(c.ToString());

Outputs:

3123

Which really makes it *look like* a dynamic type.

I've noticed that with dynamic -- it tends to be infectious. I've found it's useful for dealing with JSON and all that gooey webishness. :)
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: An experiment about static and dynamic type systems
« Reply #6 on: September 14, 2011, 02:35 PM »
C# allows dynamic typing, but I'll be damned if I'll use it if I can at all avoid it. (dynamic and var)
'var' is not dynamic typing, it's used for static type inference which is super useful for DRY reasons.

'dynamic' is something to be very careful about - it tends to ripple out if you start using it.
I stand corrected. :)

But close enough. When you look at it, var looks like a dynamic type. e.g. var acme = "Rocket Skates"; vs. var acyou = 500;
Sure, it does look like dynamic types at first, but the distinction is super-important. I personally loathe dynamic typing, but I'm a big fan of type inference, as it makes my life easier without giving up static typed goodness.

I'm not using it everywhere, though - I don't use 'var' when dealing with simple built-in types, and whether to use it when assigning a variable to a method return value isn't always clear-cut either. The goal to strive for is reducing unnecessary clutter, while not adding ambiguity; remove noise so you can focus on the important parts.

Your strings and numbers" samples show that implicit type conversions and operator overloading isn't always a good idea - and, especially since C# has such nice string formatting, it int-to-string conversion should IMHO have been explicit.

I've noticed that with dynamic -- it tends to be infectious. I've found it's useful for dealing with JSON and all that gooey webishness. :)
Can't get by just with anonymous types? :)
- carpe noctem