digitalmars.D - reddit discussion on article by bearophile
- Andrei Alexandrescu (2/2) Nov 16 2011 http://www.reddit.com/r/programming/comments/me6a5/some_examples_of_stro...
- Kagamin (13/16) Nov 16 2011 Those are examples of shitty C coding... if I wanted something akin to w...
- Andrei Alexandrescu (3/19) Nov 16 2011 Heh heh... took me a few seconds to figure out what you meant.
- Kagamin (2/3) Nov 16 2011 It actually DOES compile because `yellow` and `blue` are in enum previou...
- Andrei Alexandrescu (3/6) Nov 16 2011 This is actually a pretty awesome fail.
- bearophile (15/16) Nov 17 2011 Derived from those thoughts, an idea for Phobos, a bitFlags function:
- Timon Gehr (20/32) Nov 17 2011 Hmm. How would that work? A and B don't have an own type.
- bearophile (5/20) Nov 17 2011 Right, but I don't know if I will ever need this.
- Somedude (11/16) Nov 16 2011 Someone brought up a problem I had thought about a few days ago.
- Jesse Phillips (11/16) Nov 17 2011 I don't know any links off hand, but it has been concluded with a couple...
- Caligo (3/6) Nov 17 2011 Those nested for-loops are painful to look at.
- bearophile (4/5) Nov 17 2011 I think they aren't so bad in that code. Problems like that can be solve...
http://www.reddit.com/r/programming/comments/me6a5/some_examples_of_strong_static_typing_in_d/ Andrei
Nov 16 2011
Andrei Alexandrescu Wrote:http://www.reddit.com/r/programming/comments/me6a5/some_examples_of_strong_static_typing_in_d/ AndreiThose are examples of shitty C coding... if I wanted something akin to what he wrote I'd do this #define ENTRY(name, val) { (1<<val), #name }, then do struct { unsigned long val; const char *name; } entries[] = { ENTRY(0, yellow) ENTRY(1, blue) ... }; Haha... He's unlucky if this compiles (and it can).
Nov 16 2011
On 11/16/11 10:34 AM, Kagamin wrote:Andrei Alexandrescu Wrote:Heh heh... took me a few seconds to figure out what you meant. Andreihttp://www.reddit.com/r/programming/comments/me6a5/some_examples_of_strong_static_typing_in_d/ AndreiThose are examples of shitty C coding... if I wanted something akin to what he wrote I'd do this #define ENTRY(name, val) { (1<<val), #name }, then do struct { unsigned long val; const char *name; } entries[] = { ENTRY(0, yellow) ENTRY(1, blue) ... }; Haha... He's unlucky if this compiles (and it can).
Nov 16 2011
Andrei Alexandrescu Wrote:Heh heh... took me a few seconds to figure out what you meant.It actually DOES compile because `yellow` and `blue` are in enum previously defined with their respective values 1<<0 and 1<<1, he tried to construct a value-to-string map.
Nov 16 2011
On 11/16/11 11:42 AM, Kagamin wrote:Andrei Alexandrescu Wrote:This is actually a pretty awesome fail. AndreiHeh heh... took me a few seconds to figure out what you meant.It actually DOES compile because `yellow` and `blue` are in enum previously defined with their respective values 1<<0 and 1<<1, he tried to construct a value-to-string map.
Nov 16 2011
Andrei Alexandrescu:This is actually a pretty awesome fail.Derived from those thoughts, an idea for Phobos, a bitFlags function: http://d.puremagic.com/issues/show_bug.cgi?id=6946 A desire: http://d.puremagic.com/issues/show_bug.cgi?id=6916 Example: import std.stdio; enum : int { A, B } void main() { writeln(B); // I'd like it to print "B" here. } I think this is related to: http://d.puremagic.com/issues/show_bug.cgi?id=5004 Bye, bearophile
Nov 17 2011
On 11/17/2011 09:33 AM, bearophile wrote:Andrei Alexandrescu:Hmm. How would that work? A and B don't have an own type. Your program is equivalent to import std.stdio; enum A = 0; enum B = 1; void main() { writeln(B); // prints 1 because B is replaced with 1. } You could use mixins to automatically generate alias E.A A; alias E.B B; // ... for a given enumerated type. import std.stdio, ...; enum E : int { A, B } mixin Import!E; void main() { writeln(B); // prints "B" }This is actually a pretty awesome fail.Derived from those thoughts, an idea for Phobos, a bitFlags function: http://d.puremagic.com/issues/show_bug.cgi?id=6946 A desire: http://d.puremagic.com/issues/show_bug.cgi?id=6916 Example: import std.stdio; enum : int { A, B } void main() { writeln(B); // I'd like it to print "B" here. }
Nov 17 2011
Timon Gehr:Hmm. How would that work? A and B don't have an own type. Your program is equivalent to import std.stdio; enum A = 0; enum B = 1; void main() { writeln(B); // prints 1 because B is replaced with 1. }Right, my mental model of nameless enums was very wrong. I was thinking of them more like symbols (all nameless enums aren't grouped under a common name).You could use mixins to automatically generate alias E.A A; alias E.B B; // ... for a given enumerated type.Right, but I don't know if I will ever need this. Bye and sorry, bearophile
Nov 17 2011
Le 16/11/2011 17:57, Andrei Alexandrescu a écrit :http://www.reddit.com/r/programming/comments/me6a5/some_examples_of_strong_static_typing_in_d/ AndreiSomeone brought up a problem I had thought about a few days ago. I quote (emphasis by me):However, I am not much of a fan of D. I prefer c++ more because itdoesn't even try and memory manage, whereas in D it is optional. *I do not like this because you end up using libraries which use the GC* and I think that ruins a sort of elegance you get from select right kind of smart pointer for as specific usage. Given that D boasts that you can choose to *not* use the GC, shouldn't Phobos strive to resort to manual memory management ? I supposed this has already been discussed, but just in case I missed the discussion, could someone give a link to it ?
Nov 16 2011
On Wed, 16 Nov 2011 22:59:35 +0100, Somedude wrote:Given that D boasts that you can choose to *not* use the GC, shouldn't Phobos strive to resort to manual memory management ? I supposed this has already been discussed, but just in case I missed the discussion, could someone give a link to it ?I don't know any links off hand, but it has been concluded with a couple points. - When you have small limited memory, then custom containers and algorithms would be created for the task at hand. - When performance is needed, allocating upfront is what's needed. - The compiler, I believe confirmed by Walter, will have a switch which warns/errors when using GC expecting features. - Phobos can be extended to make manual management easier. So we just need some people to pick up the last two and create some pull requests.
Nov 17 2011
On Wed, Nov 16, 2011 at 10:57 AM, Andrei Alexandrescu < SeeWebsiteForEmail erdani.org> wrote:http://www.reddit.com/r/**programming/comments/me6a5/** some_examples_of_strong_**static_typing_in_d/<http://www.reddit.com/r/programming/comments/me6a5/some_examples_of_strong_static_typing_in_d/> AndreiThose nested for-loops are painful to look at.
Nov 17 2011
Caligo:Those nested for-loops are painful to look at.I think they aren't so bad in that code. Problems like that can be solved with hard-coded code or with generic and more flexible code. The code shown is more toward hard-coded. Feel free to write a different solution, with fewer nested loops. Bye, bearophile
Nov 17 2011