How convice people that D it's wonderfull in a hour ?
Recently I've been asked if I could give a speech about D in my university. It will be of one hour of long. I not respond yet, but I think that I will do it. Actually I have the problem that I don't know well how explain well too many features and things of D that I like. I think that only talking about D's arrays and type system I will need around half-hour. Any recommendation of how I should focus it ?
-release compiler switch and associative arrays
I understand from the documentation that the -release compiler switch turns off array bounds checking for system and trusted functions. Is it correct that the following code should seg fault when compiled with -release ? string[string] h; h[abc] = def; string s = h[aaa]; I.e. retrieving from an associative array for a non existent key. I would have thought that an exception should be generated in this case when compiled with -release (as it is when compiled without). This code behaves the same when compiled by both D1 and D2. Should I report this as a bug ?
Re: How convice people that D it's wonderfull in a hour ?
On 09/10/2011 11:00, Zardoz wrote: Recently I've been asked if I could give a speech about D in my university. It will be of one hour of long. I not respond yet, but I think that I will do it. Actually I have the problem that I don't know well how explain well too many features and things of D that I like. I think that only talking about D's arrays and type system I will need around half-hour. Any recommendation of how I should focus it ? My best advise would be to assume everyone is closed-minded, has a favorite language, and has no intention to switch away from it or try anything different. Don't try and sell D to them, just tell them about it - trying to tell them/imply D is better will cause them to dislike it for no real reason. If you can get some audience participation in there then you can judge how they're reacting to it and adjust as necessary. As for content, assuming everyone has a decent general knowledge of programming in general, I'd talk about cool stuff that D can do that other languages can do but in more difficult ways. Talk about things that can go well beyond the scope of your talk so people can go away and try it after if they like. I advise you refer to some of Andrei's talks for ideas, you can generally see how well things work/don't work based on questions from the audience/Andrei's responses. I forget the topic, but there's definitely been a couple of occasions where Andrei didn't have a decent response (free copies of TDPL were given out as a result ;)). -- Robert http://octarineparrot.com/
Re: -release compiler switch and associative arrays
On 09-10-2011 13:24, Graham Cole wrote: I understand from the documentation that the -release compiler switch turns off array bounds checking for system and trusted functions. Is it correct that the following code should seg fault when compiled with -release ? string[string] h; h[abc] = def; string s = h[aaa]; I.e. retrieving from an associative array for a non existent key. I would have thought that an exception should be generated in this case when compiled with -release (as it is when compiled without). This code behaves the same when compiled by both D1 and D2. Should I report this as a bug ? To generate a sensible exception in the first place, you'd have to actually *do* bounds checking. When you disable bounds checking, you're just allowing it to read/write beyond the bounds of the array, which any sane OS won't be too happy with. :) - Alex
Re: How convice people that D it's wonderfull in a hour ?
On 09.10.2011 14:00, Zardoz wrote: Recently I've been asked if I could give a speech about D in my university. It will be of one hour of long. I not respond yet, but I think that I will do it. Actually I have the problem that I don't know well how explain well too many features and things of D that I like. I think that only talking about D's arrays and type system I will need around half-hour. Any recommendation of how I should focus it ? Depending on the audience if I'd be giving a talk to a gang of C++ programmers I'd try to focus on small separate cool topics like: -arrays slices, with optional GC -delegates nested functions -scope(exit/success/failure) -simple uses of CTFE Then maybe clean template with static if template constraints, maybe variadic template and alias params, maybe codegen with string mixin. Stuff like typeof(...) and __traits usually blows mind off way too early. Based on my (limited) experience with fellow programmers it's only hurts to go into greater detail, it causes thoughts like 'as huge as C++ and with a pack of new pitfalls' and little to no enthusiasm. So you'd have to place your bet on a few prime features (e.g. 3 like in one of Andrei talk). And then you can casually present a short list of other cool features and say a thing or two about them, not forgetting that there is even more. -- Dmitry Olshansky
ref struct?
(I show this here because it's probably a silly idea, but it may a chance to learn something.) Do you like the idea of a POD that is always managed by reference, as class instances? ref struct Foo {} static assert(Foo.sizeof == 1); void main() { Foo f1; // void reference Foo f2 = new Foo; // by reference } It is as light as a struct, but you don't need to use the pointer syntax to manage a Foo instance, the code is cleaner. There is no info field inside a ref struct, so in some situations the destructor doesn't get called, like regular structs. Bye, bearophile
Re: How convice people that D it's wonderfull in a hour ?
Talk about stuff that's hard to do or impossible in C++ (or just a PITA like the whole language) and compare it to some nifty D code. For example template metaprogramming. No easy way to do template constraints, no is expressions nor a proper typeof so you have to use specialization a lot. You could also show something that checks for an interface at compile-time, like template isInputRange(R) { enum bool isInputRange = is(typeof( { R r; // can define a range object if (r.empty) {} // can test for empty r.popFront(); // can invoke popFront() auto h = r.front; // can get the front of the range }())); } CTFE is another strong feature. You could for example show some code that generates Token handling code (an enum for the tokens, associative arrays for token 2 string and the other way around, etc.) to be used by a lexer without the necessity for a DSL like in Clang or a separate tool like dmd.
Re: ref struct?
I think this is what refcounted structs are for.
Re: How convice people that D it's wonderfull in a hour ?
Things that really convince me are comparisons with already existing stuff. Show what the problems are with an example program like c++ or java and show how d resolves the issue. Be careful though, one of the first things that put me off is when I feel it's too biased and they only show possitive points. if something is too good to be true it usually is show them how open D is to multiple programming paradigms and how well it is integrated in the language. show them the shining points of D like it's array's or CTFE. show how beautifully the syntax looks compared to c++. Show them that with D you can write high level but go low level very easily if you need it. Just playing with ideas here :)
Re: ref struct?
On Sunday, October 09, 2011 22:42:35 Andrej Mitrovic wrote: I think this is what refcounted structs are for. That or make it a class and make it final. - Jonathan M Davis
Re: How convice people that D it's wonderfull in a hour ?
Le 09/10/2011 12:00, Zardoz a écrit : Recently I've been asked if I could give a speech about D in my university. It will be of one hour of long. I not respond yet, but I think that I will do it. Actually I have the problem that I don't know well how explain well too many features and things of D that I like. I think that only talking about D's arrays and type system I will need around half-hour. Any recommendation of how I should focus it ? I think you should show through several exemples. AS IT IS UNIVERSITY, I guess your public will know about programming. Explain difference between struct and classes, and how it is great compared to C++ (no slicing for exemple). Show some stuffs about first class function and delegates (for callback for exemple) coppared to how painful it is in C++ or java (using interface and useless object) Then, gove a talk aboit metaprogramming (how you can implement behaviral pattern with no cost at runtime, how you can make very generic code like STL) and why it is way better than C++ (usability with stuffs like static if) or java (generic isn't metaprogramming). And last but not least : explain memory model and how it help to deal with multithrading problems where other languages usually aren't good. The point isn't to bash C++ or java, but to show how some problem you face in thoses languages can be solved elegantly in D. If your public knows others languages than java and C++, then adapt the speach to what they know.
Re: How convice people that D it's wonderfull in a hour ?
On 10/9/2011 5:18 PM, deadalnix wrote: Le 09/10/2011 12:00, Zardoz a écrit : Recently I've been asked if I could give a speech about D in my university. It will be of one hour of long. I not respond yet, but I think that I will do it. Actually I have the problem that I don't know well how explain well too many features and things of D that I like. I think that only talking about D's arrays and type system I will need around half-hour. Any recommendation of how I should focus it ? I think you should show through several exemples. AS IT IS UNIVERSITY, I guess your public will know about programming. Explain difference between struct and classes, and how it is great compared to C++ (no slicing for exemple). Show some stuffs about first class function and delegates (for callback for exemple) coppared to how painful it is in C++ or java (using interface and useless object) Then, gove a talk aboit metaprogramming (how you can implement behaviral pattern with no cost at runtime, how you can make very generic code like STL) and why it is way better than C++ (usability with stuffs like static if) or java (generic isn't metaprogramming). And last but not least : explain memory model and how it help to deal with multithrading problems where other languages usually aren't good. The point isn't to bash C++ or java, but to show how some problem you face in thoses languages can be solved elegantly in D. If your public knows others languages than java and C++, then adapt the speach to what they know. The threading model is what attracted me to D.