DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: An experiment about static and dynamic type systems  (Read 10,371 times)

Armando

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


[attach]
"I suppose it can be said that I'm an absent-minded driver. It's true that I've driven through a number of red lights on occasion, but on the other hand, I've stopped at a lot of green ones but never gotten credit for it."
Glenn Gould

f0dder

  • [Well, THAT escalated quickly!]
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
    • Participated in NANY Challenge Once
Re: An experiment about static and dynamic type systems
« Reply #1 on: September 13, 2011, 12:00 AM »
Haven't had the time to look at this in detail, but the following caught my attention:
Quote
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
    • Coding Snacks
Re: An experiment about static and dynamic type systems
« Reply #2 on: September 13, 2011, 12:40 AM »
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
"I suppose it can be said that I'm an absent-minded driver. It's true that I've driven through a number of red lights on occasion, but on the other hand, I've stopped at a lot of green ones but never gotten credit for it."
Glenn Gould

Renegade

  • Tell me something you don't know...
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,291
    • Participated in NANY Challenge Three Times
    • Furry Fandom Badge - Furry Fandom
    • Linux User
Re: An experiment about static and dynamic type systems
« Reply #3 on: September 13, 2011, 04:21 AM »
...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

  • [Well, THAT escalated quickly!]
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
    • Participated in NANY Challenge Once
Re: An experiment about static and dynamic type systems
« Reply #4 on: September 13, 2011, 06: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

  • Tell me something you don't know...
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,291
    • Participated in NANY Challenge Three Times
    • Furry Fandom Badge - Furry Fandom
    • Linux User
Re: An experiment about static and dynamic type systems
« Reply #5 on: September 13, 2011, 10: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.microsoft.com/en-us/library/bb383973.aspx

Quote
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.microsoft.com/en-us/library/bb384061.aspx

Quote
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: (csharp)
var a = 1;
var b = "123";
var c = a + b;
MessageBox.Show(c.ToString());

Outputs:

1123

And

Code: (csharp)
var a = 1;
var d = a + 2;
var b = "123";
var c = d + b;
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

  • [Well, THAT escalated quickly!]
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
    • Participated in NANY Challenge Once
Re: An experiment about static and dynamic type systems
« Reply #6 on: September 14, 2011, 07: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

Original address: https://www.donationcoder.com/forum/index.php?topic=27956.0