Possible solution to template bloat problem?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Aug 20 14:52:28 PDT 2013
On 8/20/13 2:22 PM, Ramon wrote:
> Today, some hundred (or thousand?) hours of painful search for bugs or
> problems later due to things like '=' in an if clause, I'm ready to
> admit that any language using '=' for assignment rather than, for
> instance, ':=' is effectively creating a trap for the people using it.
>
> Today I look at Ada and Eiffel with great respect.
void main() {
int a, b;
if (a = b) {}
}
./test.d(4): Error: assignment cannot be used as a condition, perhaps ==
was meant?
This is a solved problem. (However see also
http://d.puremagic.com/issues/show_bug.cgi?id=10862 which I just
submitted). I haven't heard a peep about it in D and C++ circles (most
C++ compilers define a similar warning, although they aren't required).
> I've seen hints from the authors of D themselves that '++' and '--'
> might not be the wisest way of action. So I stand here asking "Why the
> hell did they implement them?"
That would be news to me. I find "++" and "--" very useful for daily
use. D also implements their overloading arguably in a more elegant way
than C++ does.
> It would be very simple to implement that logic in an editor for those
> who feel that life without '++' is impossible to automagically expand
> "x++" to "X := x + 1".
This argument is unlikely to do very well with this crowd.
> Having seen corporations in serious trouble
> because their system broke (or happily continued to run albeit producing
> erroneous data ...) for this "small detail" I have a hard time to defend
> '++'. ("Save 5 sec typing/day and risk your company!").
Very interesting! What pernicious effects does "++" have?
> Another issue (from an Ada background): Why "byte" ... (the complete
> series up to) ... "cent"? Bytes happen to be important for CPUs - not
> for the world out there. I wouldn't like to count the gazillion cases
> where code went belly up because something didn't fit in 16 bits. Why
> not the other way around, why not the whole she-bang, i.e., 4 (or) 8
> bytes as default for a single fixed point type ("int") and a mechanism
> to specify what actually is needed?
> So for days in a month we'd have "int'b5 dpm;" (2 pow x notation) or
> "int'32dpm;"?
As a rule of thumb primitive types model primitive machine types. For
everything else there are libraries. Or should be :o).
> Even funnier, even D's authors seems to have had thoughts
> in that direction (but not following them) when designing the dyn array
> mechanism where a dyn array effectively has 2 pow x based de facto
> storage (size 6 (elements officially used) de facto is an 8 element array).
Exponential growth for O(1) amortized append has nothing do to with
basic data sizes.
> This happens to be a nice example for perspective. C's perspective (by
> necessity) was resource oriented along the line "offer an 8bit int so as
> to not waste 16bits were 8bits suffice".
> Yet we still do that in the 21st century rather than acting more *human
> oriented* by putting the decision for the size to the human. Don't
> underestimate that! The mere action of reflecting how much storage is
> needed is valuable and helps to avoid errors.
There's very much wrong in this. Byte-level access is necessary in a
systems language for a variety of reasons, of which storing individual
integers is probably the least interesting.
> D is, no doubts, an excellent and modern incarnation of C/C++. As far as
> I'm concerned D is *the* best C/C++ incarnation ever, hands down.
>
> But is '=' really a holy issue? Would all D programmers have run away if
> D had ':=' as assignment op?
Deprecating "=" in favor of ":=" would solve a problem that doesn't
exist, and would create a whole new one.
> I wish, D had done all the miraculos things it did - and then on top,
> had allowed itself the luxury to be more human centric rather than
> sticking to a paradigm that was necessary 50 years ago (and even then
> not good but necessary)
I understand we all have our preferences, but reifying them to absolutes
is specious. If you said "Yo dudes, I don't dig '=' for assignments and
'++' and '--' for {inc,dec}rement. Also I don't give a rat's tail on dem
fixed small integers. Other that dat, y'all boys did a rad job. Peace."
- well that would have been easier to empathize with.
> BTW: I write this because D means a lot to me not to bash it. For Java,
> to bname an ugly excample, I never wasted a single line of criticism;
> t'sjust not worth it. So, please, read what I say as being written in a
> warm tone and not negatively minded.
Awesome, thank you and keep destroying.
Andrei
More information about the Digitalmars-d
mailing list