[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strong Typing, Dynamic Languages, What to do?

"Anton van Straaten" <anton@appsolutions.com> writes:

> Oscar Fuentes wrote:
> > As Chris U. said, it is debatable if the type system must do
> > bounds checking.
> That's mainly because it's hard to do bounds checking statically, so
> it's commonly ignored in languages which primarily rely on static
> type checking, like C++.  But for a type system to provide safety
> for its types, it must do bounds checking, since otherwise, it can't
> protect the integrity of its own types.

Ok, you can do run-time bounds checking if you wish.

> C++ does the best it can to warn you at compile time of the type
> errors it can detect, but it isn't foolproof.  That's why C++ is
> called an "unsafe language".  The important point is that it can't
> always protect the integrity of its own types, in particular because
> the language itself performs few runtime checks.  I think that's the
> real point here.

I know that C++ allows legal violations of the type system.

> > I can understand the POV of some people here which are academics
> > teaching how to program well to future professionals.
> The problem goes much further than that.  The costs of developing,
> debugging and maintaining C/C++ programs are much higher because of
> this kind of thing.

Speaking from my personal experience, I strongly disagree. It's
perfectly possible to do "elegant" (modulo syntactic aesthetics),
reliable, maintainable, extensible C++ code. It's only that that
idioms are not common knowledge among most C++ coders, which are still
heavily influenced by the C past of C++.
> > If you want to do type safe programming in C++ you can do it
> > and the compiler will help you. The only requirement is that
> > you must know what are you doing.
> If you "know what you are doing", you don't need a type system at
> all (think pure untyped lambda calculus, bay-bee! :)

Sure some folks would work without type system, but I doubt that
anyone could want to do a real-world application with pure untyped
lambda calculus (and much less if he is entitled to _maintain_ it!)

> A type system that relies on you to implement it properly isn't
> doing the job for which type systems are intended.

No, it's the other way around: you rely on the type system to verify
that the code you write does not break types _when_ _you_ _dont't_
_want_ _to_. The C++ constructs that jumps over the type system is so
evident that it is easy to avoid. If you ask me to program Scheme
without using continuations on the code I write I know what I must

> C++ does its best with static checks - and runtime checks in some
> very specific cases, such as safe casts - but that's not enough for
> true type safety.

Ok, I see your point. It's merely a semantics question. C++
programmers doesn't want type-safety in the "down-your-throat" sense
and on other communities type-safety is not type-safety as long as the
programmer can break it.