Re: dynamic vs. static: the age-old debate
- From: "Curtis W" <cwarren89@xxxxxxxxx>
- Date: 27 Aug 2006 19:31:56 -0700
How can you be sure of this? What is your definition of "staticallyOther than that, it does everything yours does
Yours doesn't statically check to the same degree
check"?
and will be many times slower.And many times more extensible.
No, that was the more readable version. The compacted version would beand has the same length.
Yours is 18 LOC and incomplete, my OCaml is 14 LOC and my Mathematica is 11
LOC and also incomplete.
exactly the same length with the 3 lines added. If my language had let
rec support built in, then it would have exactly the same functionality
in your version, although I fail to see the need for such a construct
when generators are available.
How is it possible to write something in a language that does notbut yours wasn't doing the same thing as mine.
Until you post code than actually works, you can't reasonably make such
claims.
How do you know it doesn't work?
Because it is known to be incomplete and is written in a language that
doesn't exist.
exist? Doesn't the presence of such a program prove that said language
does, indeed exist? A compiler or interpreter might not be available,
but it's perfectly possible to "run" it by hand. After all, your brain
is turing complete.
Which is only made trivial in your version because it happens to beIt's clear enough to be verifiable by hand,
Except for the non-trivial bit that is missing, yes.
built in to the language. In fact, the only reason it's needed at all
is because you're practically rewriting the host language in itself--if
you were to write a python interpreter, for example, there would be
several non-trivial bits that you'd have to write from scratch.
Generators are a concept from python, not OO. They're basicallyeven if it doesn't compile directly. In fact, I've even shown you
how to convert it to python so you _can_ run it.
If I translate it myself and work out how to "use generators", whatever kind
of depraved OO design pattern they are.
functions which stream data back instead of returning it all at once,
e.g.:
def get_nums():
while True:
num = int(raw_input())
yield num
This basically returns an iterator which lets you iterate over the
users input in a lazy manner.
Of course. Let's say I want to add a 'print' function and a new type ofWhy?
To attain the same level of flexibility present in my version you'd
have to either 1) pass around all functions which operate on the data
or 2) pass around a struct or its equivalent.
That is what you believe I would have to do. I believe you are wrong.
Can you challenge me with some way that you want to extend the functionality
of this program that you believe will be easier to add using OOP? Then we
can both have a go and compare the results objectively.
expression. (it doesn't matter what kind--take your pick :)
Perhaps, but you still have to pass them around at the callsite, don'tThe first one is still
rather inflexible in that you have to update all function definitions
every time you add a function,
Not if you use a functor, for example.
you?
This is academic anyway, I can see no reason to "pass around allOr if you want to leave the door open to extension later on without
functions..." unless I want a higher-order function.
having to rewrite a large portion of code.
I have no idea what that does. Could you possibly describe theHehe. Humor me, how is it less extensible in "many useful ways"?
The ones I already enumerated twice:
parallel pattern matching
variable binding
structure matching
or-patterns
guarded patterns
static checking
algorithmic matching
...
I doubt any of those are particularly verbose when implemented using
classes.
Here is another counter example:
The following Mathematica code implements polynomial integration using only
Mathematica's pattern matcher and the FreeQ[e, f] function (which checks
that the pattern "f" does not match any subexpression of "e"):
integrate[y_ + z_, x_] := integrate[y, x] + integrate[z, x]
integrate[c_ y_, x_] := c integrate[y, x] /; FreeQ[c, x]
integrate[c_, x_] := c x /; FreeQ[c, x]
integrate[x_^n_., x_] := x^(n + 1)/(n + 1) /; FreeQ[n, x] && n != -1
For example:
integrate[3 a x^2 + 2 b x + c, x]
=> c x + b x^2 + a x^3
Just doing that exploits tremendous sophistication in the pattern matcher,
far beyond the capability of OOP.
algorithm in a bit more detail?
Given that this is more complicated and more error prone than the previousI'll put up a python version once I figure out what it does, which
example, it is essential that the translation can be executed.
should be useful to show that the version in my language is correct. I
doubt I'll have to use any facilities not present in python, so mine
should be almost identical except less verbose.
.
- Follow-Ups:
- Re: dynamic vs. static: the age-old debate
- From: Jon Harrop
- Re: dynamic vs. static: the age-old debate
- References:
- Re: dynamic vs. static: the age-old debate
- From: Curtis W
- Re: dynamic vs. static: the age-old debate
- From: Jon Harrop
- Re: dynamic vs. static: the age-old debate
- From: Curtis W
- Re: dynamic vs. static: the age-old debate
- From: Jon Harrop
- Re: dynamic vs. static: the age-old debate
- From: Curtis W
- Re: dynamic vs. static: the age-old debate
- From: Jon Harrop
- Re: dynamic vs. static: the age-old debate
- From: Curtis W
- Re: dynamic vs. static: the age-old debate
- From: Jon Harrop
- Re: dynamic vs. static: the age-old debate
- From: Curtis W
- Re: dynamic vs. static: the age-old debate
- From: Jon Harrop
- Re: dynamic vs. static: the age-old debate
- From: Curtis W
- Re: dynamic vs. static: the age-old debate
- From: Jon Harrop
- Re: dynamic vs. static: the age-old debate
- From: Curtis W
- Re: dynamic vs. static: the age-old debate
- From: Jon Harrop
- Re: dynamic vs. static: the age-old debate
- From: Curtis W
- Re: dynamic vs. static: the age-old debate
- From: Jon Harrop
- Re: dynamic vs. static: the age-old debate
- Prev by Date: Re: dynamic vs. static: the age-old debate
- Next by Date: Re: dynamic vs. static: the age-old debate
- Previous by thread: Re: dynamic vs. static: the age-old debate
- Next by thread: Re: dynamic vs. static: the age-old debate
- Index(es):
Relevant Pages
|