Structures are NOT a new datatype
- Posted by Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> Jan 31, 1999
- 435 views
First of all, structures are already implemented. We just call them sequences now are able to change their *structure* all the time. But I dont want to change the structure. This involves a long type check, which checks the lengh and type and possibly the sub-type of every element in the sequence. This all to avoid some silly mistakes. Result: nobody writes such type checks, and just debugs through print statements and the tracer, since the actual origin of the problem has not been found. (a wrong value in a type, normally, would show up much later in the program, totally unrelated to where the 'bug' is, while with a type check, the bug is caught where it occurs, rather than where it first brakes your code ). So what _do_ I do want ? Two things: * constants declared local to a sequence for slicing only. * the ability to define a structure at once, without the need of building it up using dynamic routines and to assign a type to each element of a sequence. So, not a new language element. But a new feature. A new syntax rather. A new way of doing something we already can. Why ? More readable. Better maintainable. The same goes for arrays. They already exist in the form of sequences. I just want the interpreter to be so smart to read this: type byte (integer x) return x >= 0 and x < 256 end type byte namespace[20] = ' ' ..... to read that as... type specific_type_for_ns (sequence s) if length(s) != 20 then return 0 end if for index = 1 to 20 do if not byte (s[index]) then return 0 end if end for end type specific_type_for_ns ns ns = repeat (' ', 20) ----- Well, let me guess, you purist Euphorians...... You thought the second example was more readable and can be much better optimized! Why is there a repeat function in Euphoria, while you could just do: sequence ms ms = "" for index = 1 to 20 ms = append(ms, ' ') end for Well, for two reasons: - better readable (repeat (' ', 20) is much more logical) - it can be optimized enormously. And for the same two reasons I want arrays & structures, yet now these arguments are considered insufficent! Or is the real difference, that C does not have a repeat statement ? What the hell does C got to do with the discussion anyway ? Ralf