- Manual memory management. W. T. F?
Yes,
And that automatically disqualifies it as a modern language, full stop.
That sentiment pretty well sums up a huge part of what’s wrong with
modern programming. People think that important tasks ought to be
done for them instead of learning how to do them right, so they take
what should be their own responsibility and hand it off to some
bloated library that’s not capable of doing it correctly.
We’re talking about /memory management/. The following is a very common
idiom, perhaps the most common resource management idiom:
x = alloc_resource()
…
free_resource(x)
// End of block.
It’s also a stupid idiom because it clutters the code. This following
is much better:
x = alloc_resource()
…
// End of block - ‘x’ is automatically freed.
Why shouldn’t this be automated? It’s an absolutely trivial task!
There is no way a language facility could mess this up! If you can’t
trust your compiler to produce optimal code in this case, then you can’t
trust your compiler at all.
Now, if you want to free ‘x’ before the end of the block - fine, do
that. Nobody’s stopping you. But the case where ‘x’ is freed at the
end of the block is common enough to deserve special treatment.
What do you mean by that? Sure, you can encapsulate it in some other
function (smart pointers, for example), but you can’t eliminate it.
I mean this:
{
some_ptr p = create();
} // Resource automatically freed at end of scope.
Programming is the process of automating tasks. You don’t want to
create machine code from hand, so you write a compiler to do it for you.
You don’t want to insert the algorithm for calculating the square root
a dozen times in your program, so you write a function to calculate the
square root for you and call that function a dozen times. You don’t
want to write a dozen allocate/free pairs in your program, so you write
a RAII type that automatically frees the resource for you.
The question isn’t if the language automates the task. The question is
if the language gives you the facilities to automate the task.
As I recall (and my memory could be faulty), type equivalence is by
name, not structure. Sure, you can declare a variable as a pointer,
but it won’t be assignment-compatible with any other pointers declared
elsewhere, which makes the functionality useless.
Depends on the compiler settings. You’re kind of close, but it’s nowhere
near as strict as you make it out to be. And even if it was, that doesn’t
make the functionality useless. The standard idiom is to declare a named
pointer type right next to the declaration of the record it points to, so that
any code that uses the unit with the record declaration gets the pointer
declaration as well, and there’s no confusion.
More useless typing. Even more useless typing if you want a pointer to
a pointer, or a pointer to an array, or an array of pointers, or a
pointer to an array of pointers, etc…
But why are you using pointers in the first place? That’s generally
considered bad form, unless you have to interface with libraries written
in C or something like that.
I was modifying a program that uses pointers. Nothing in the world
could convince me to start a program in Delphi from scratch.
It’s useless extra typing, which is the main problem with the "classic"
statically typed languages that the dynamic languages have managed to
fix. Compare:
Python:
def f():
x = g()
h(x)
Pascal:
procedure f;
var x: Integer;
begin
x = g();
h(x);
end;
The Pascal version uses fully twice as many lines of code, and they’re
longer too.
Mmhmm. But there’s a good reason for it. In Python, you could do that,
and call g(), which returns a dictionary, and pass the result to h(), which
expects a number. In Pascal, the compiler makes sure you don’t do that.
Do you see me advocating dynamic typing anywhere? Here is the
equivalent in D:
void f() {
auto x = f();
g(x);
}
It’s larger than the Python version, but much smaller than the Pascal
version. It’s also statically typed.
BTW why not just write it like this?
procedure f;
begin
h(g());
end;
Because it’s a minimal example meant to demonstrate something, not an
actual piece of code.On 4/8/2010 05:56, Mason Wheeler wrote:
----- Original Message ----
From: Rainer Deyke
Subject: Re: [SDL] Off-Topic: Quake II Ported to HTML5
–
Rainer Deyke - rainerd at eldwood.com