Sign in to follow this  
T1Oracle

Am I the only one?

Recommended Posts

T1Oracle    100
Who loves strongly typed languages and static polymorphism? Maybe it's just my limited exposure, but I get this feeling that the trends are all towards weakly typed languages like C#, Java, and Ruby. Strongly typed languages turn run time errors into compile time errors thus reducing the chance that you will even see an error. They can also enforce stricter rules on the usage of an interface (or function/method) that avoid errors in understanding, implementation, and usage. I am all for more descriptive (not more syntactically verbose, I like brackets over "end if") languages. The more descriptive the language, the more clear its meaning. When programmers understand the meaning of the code they are much less likely to misuse it. More descriptive languages also tend to give the compiler more information which could be used for optimizations.

Share this post


Link to post
Share on other sites
Mike.Popoloski    3258
So what your saying is if someone made a class called Object in C++ and derived all of his classes from it, C++ would no longer be strongly typed?

I think you really don't have any idea of how C# or Java operate. Just because there is a base class called Object doesn't mean the compiler doesn't know the type of the object when it is instantiated.

Share this post


Link to post
Share on other sites
dbzprogrammer    100
Don't get me wrong, I am a fan of strong OO and good design, but...

I'm one of those programmers who loves low level control, I, personally, would love my personal language to have types, but not great enforcement of them. Why? Because I tend to code in a safe way.

My main example of this is flexibility. I will commonly need an object that's been passed to a function to be ambiguous. While polymorphism and inheritance may work well here, I'll sometimes just have the Base class have a Type specifier and function pointers. No virtual table if/then lookups, just straight functionality.

Now, I am very, VERY analytical of my code. Before compiling, I will read through it quite a few times and make sure everything will plop together as it should. While this opens the door for my own error, I find that this error often doesn't come about, and it's worth the extra functionality I'm getting for those occasional errors.

Now, when I'm working in a team/group, OO & strict types ftw. As many of the other programmers have different ideas and feels to how things should be, it's nice to have a common standard that you can rely on everyone using.

Share this post


Link to post
Share on other sites
SiCrane    11839
Quote:
Original post by T1Oracle
Because they have a type called "Object" there is no such thing as a generic object.

What do you consider to be a strongly typed language then? Obviously you can't mean C or C++ since they have the void * type.

Share this post


Link to post
Share on other sites
Nitage    1107
You aren't alone - I go out of my way to create code that will fail at compile time rather than run time wherever possible whenever I'm using C++ (altough you're talking about static vs dynamic typing, not strong vs weak).

Don't underestimate the power of dynamically typed languages like Python though - there are many things that you can do in a 5 line python script that you'd be crazy to attempt in C++.

Share this post


Link to post
Share on other sites
rip-off    10976
I thought like you, until I started using these languages.

I like the idea of static typed languages. There are times you want static typing, and times you don't. Static typed languages have a lot of boiler plate code you have to generate which have nothing to do with the program logic at all. I find that I write more logic (not more code! often less than the equivalent C++) in such a language given the same period of time.

Hence my current setup, C++ for my "static types", exported to Lua for all the game logic.

Yes, I have to have lots of run time error checking in case one of my C++ functions is called with ridiculous values from Lua. But you still have to do that in some places in C++.

Like everything I suppose, there is a time and a place for both types of languages.

[edit: confusion]

[Edited by - rip-off on November 23, 2007 10:50:36 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Mike.Popoloski
So what your saying is if someone made a class called Object in C++ and derived all of his classes from it, C++ would no longer be strongly typed?


C++ isn't strongly typed. If I write a function that expects a char and I give it an integer, my program will compile without error. In a strongly typed language, if you write a function that expects a char as an argument, it will take a char and only a char.

Quote:
Original post by SiCrane

What do you consider to be a strongly typed language then? Obviously you can't mean C or C++ since they have the void * type.


OCaml and Haskell are both strongly typed.

Share this post


Link to post
Share on other sites
Naku    151
Quote:
Original post by T1Oracle
Because they have a type called "Object" there is no such thing as a generic object.


What is void* a pointer to?

Share this post


Link to post
Share on other sites
Nitage    1107
Quote:

C++ isn't strongly typed. If I write a function that expects a char and I give it an integer, my program will compile without error. In a strongly typed language, if you write a function that expects a char as an argument, it will take a char and only a char.


Indeed it isn't. C++ classes are strongly typed though (as long as they don't have implicit conversion constructors or conversion operators and as long as you avoid using reinterpret_cast on them). So the typing system, like the rest of C++, is a mixture of paradigms (or an octopus made by nailing extra legs onto a dog, depending on your perspective).

Share this post


Link to post
Share on other sites
Quote:
Original post by Naku
Quote:
Original post by T1Oracle
Because they have a type called "Object" there is no such thing as a generic object.


What is void* a pointer to?


A pointer that can point to any type. Check out the void pointer section on this page.

Share this post


Link to post
Share on other sites
Zahlman    1682
Quote:
Original post by Naku
Quote:
Original post by T1Oracle
Because they have a type called "Object" there is no such thing as a generic object.


What is void* a pointer to?


Whatever happens to be at that memory location. (The code making use of the pointer has to either know, or find out by quite careful inspection).

Anyway, OP is strongly encouraged to look up the difference between strong vs weak typing and static vs dynamic typing. Among other things.

Share this post


Link to post
Share on other sites
Simian Man    1022
Quote:
Original post by Captain_Thunder
OCaml and Haskell are both strongly typed.


Yeah if you like static typing so much, I'd really recommend learning Ocaml!

Share this post


Link to post
Share on other sites
Rebooted    612
Quote:
Original post by rip-off
I like the idea of strongly typed languages. There are times you want strong typing, and times you don't. Strongly typed languages have a lot of boiler plate code you have to generate which have nothing to do with the program logic at all.
Not in general, it depends on the language. Haskell and ML for example have decidable type inference, so you can write a million line application without writing a type annotation (not even one).

FWIW, here's my rant on static vs dynamic typing debates.

Share this post


Link to post
Share on other sites
rip-off    10976
Quote:
Original post by Rebooted
Quote:
Original post by rip-off
I like the idea of strongly typed languages. There are times you want strong typing, and times you don't. Strongly typed languages have a lot of boiler plate code you have to generate which have nothing to do with the program logic at all.
Not in general, it depends on the language. Haskell and ML for example have decidable type inference, so you can write a million line application without writing a type annotation (not even one).

FWIW, here's my rant on static vs dynamic typing debates.


Argh, I got my terminology all mixed. Most of what I meant was on static / dynamic typing, not strong/weak at all.

Share this post


Link to post
Share on other sites
Rebooted    612
Quote:
Original post by rip-off
Quote:
Original post by Rebooted
Quote:
Original post by rip-off
I like the idea of strongly typed languages. There are times you want strong typing, and times you don't. Strongly typed languages have a lot of boiler plate code you have to generate which have nothing to do with the program logic at all.
Not in general, it depends on the language. Haskell and ML for example have decidable type inference, so you can write a million line application without writing a type annotation (not even one).

FWIW, here's my rant on static vs dynamic typing debates.


Argh, I got my terminology all mixed. Most of what I meant was on static / dynamic typing, not strong/weak at all.
Well, my point is ML and Haskell have static typing, but they don't require you write boilerplate code.

Share this post


Link to post
Share on other sites
mattnewport    1038
I prefer statically typed languages, and the stronger the beter. I think it's odd that you mention C# and Ruby in the same sentence as examples of weakly typed languages though. Ruby is dynamically typed, C# is statically typed and also quite strongly typed. With the recent additions to C# 3.0 like lambda functions and type inference, C# is becoming one of the nicest statically typed procedural languages (and is getting an increasingly functional flavour to it).

There's lots of things I like in Python but I find the dynamic typing problematic for anything but small utilities and scripts. I wouldn't choose it for a large system. I hate being bitten with a runtime error due to a stupid mistake that would have been caught at compile time by a statically typed language with a reasonably strong type system. With a well designed type system and good type inference I believe you can get most of the benefits of a dynamically typed language (particularly the conciseness) without the drawbacks. Functional languages like Haskell or OCaml currently represent the state of the art for strongly statically typed languages and advanced type inference but it's nice to see a mainstream language like C# increasingly moving in that direction. Even C++ has improvements on the horizon with some of the features going into C++ 0x, though it's anyone's guess when we'll start seeing those features in mainstream C++ compilers.

Share this post


Link to post
Share on other sites
T1Oracle    100
Quote:
Original post by Mike.Popoloski
So what your saying is if someone made a class called Object in C++ and derived all of his classes from it, C++ would no longer be strongly typed?

I think you really don't have any idea of how C# or Java operate. Just because there is a base class called Object doesn't mean the compiler doesn't know the type of the object when it is instantiated.

Your forgetting that both C# and Java enforce the object type upon all objects made in the language. In C++ the void type only occurs where you explicitly declare it.

Regardless, I hate "void *" as much as I hate "Object". That's what generics and templates are for. If there is a real case for "needing" something beyond the scope of what templates or generics can do, then the chances are that "void *" is better (though still hideous) anyway. "Object" is a waste.

Also, to those who mention "boiler plate" code generics/templates eliminate that. They even allow for the possibility of compiler optimization while maintaining OO type safety.

Generics are better than templates since they are more specific.

Either way, I have no intent for this to be a C++ is better than language X post because I don't believe that (although I do like C++). I just want to know if anyone else appreciates when languages enforce stronger static typing (I apologize for not mentioning static typing earlier).

It is my opinion that the more specificity that can be communicated in code and enforced at compile time, the better. I like descriptive languages that let me concisely express the functionality I need without having to force it.

Anyway, maybe I should look into OCaml or Haskel, although I don't know if I'd ever get paid to use them.

Share this post


Link to post
Share on other sites
Sneftel    1788
What's an example of an error one can make thanks to Java's type system, that C++'s "stronger" type system would prevent?

Share this post


Link to post
Share on other sites
T1Oracle    100
Quote:
Original post by Sneftel
What's an example of an error one can make thanks to Java's type system, that C++'s "stronger" type system would prevent?

Anything that uses the type Object but expects a specific kind of object is a potential for a run time error that would not occur with C++ (given that you don't use void *).

Share this post


Link to post
Share on other sites
Sneftel    1788
Quote:
Original post by T1Oracle
Quote:
Original post by Sneftel
What's an example of an error one can make thanks to Java's type system, that C++'s "stronger" type system would prevent?

Anything that uses the type Object but expects a specific kind of object is a potential for a run time error that would not occur with C++ (given that you don't use void *).

But you don't use Object either. There's the odd holdover from 1.0 like clone() and equal(), but other than those exceptions Java programmers view Object in exactly the same way that C++ programmers view void*.

Share this post


Link to post
Share on other sites
SiCrane    11839
Given that void * is as deeply embedded in the C++ language as Object is in Java, I fail to find that a convincing point in C++'s favor. For example, C++'s type system won't prevent you from passing a pointer to object to memset() or memcpy(). Java's type system at least won't let you trash the pointer to a vtable. And you can still write your functions to take a type of non-Object. No one forces you to use Object for your interfaces. You know, like how you can write a function in C++ to take a pointer of non-void type.

Share this post


Link to post
Share on other sites
Scet    960
T1Oracle, you might want to actually go try C#, because the Object class is nothing like a C void pointer.

Edit: OK it is somewhat similar, but at least an Object actually has to refer to an Object, a void* can point to anything.

Just because every class inherits it, doesn't mean you can just assign anything you want.

For example:


public class A : Object { /*code*/ }

public class B : Object { /*code*/ }

//somewhere else
A A_Instance = new A();
B B_Instance = A; // <- doesn't work, compiler error


Now I could make B_Instance an Object type, which would work. However doing so is considered bad practice.

Hell you can't even basic types to another without doing casts, unlike in C or C++.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this