June 11, 2002 Re: enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew Wilson | Matthew Wilson wrote:
> And a very good thing too. Now if we can wean all the terse programmers away from all their other write-once unmaintain-ever-more practises, we should really be cooking
Reminds me of my own torrid programming past. As a deeply-embedded C programmer for 20 years now, one who was brought up on assembler, I still have this craven need to write monstrously complex functions in two or three lines of impenetrable obfuscated C. The goal is to do the most with the fewest keystrokes, yet make the fastest possible code.
My peers hated it. My bosses hated it. When I became independent, my clients hated it. But you see, sometimes I just had to do it. I couldn't resist. I want to push C down to the level of finely honed assembly macros (which can get positively Forth-like if left to their own devices). And if the rest of the world couldn't understand it, well, it just proved they didn't really know C all that well. Right?
To make everyone shut up, I started putting the "correct" code in there as well, then I'd use the preprocessor to switch between the two instances. I could show the two were functionally equivalent (and on some occasions they even produced the same code).
Well, compilers got smarter, the style battles got harder to fight, and programmers got dumber (in a good way ;^). Simple straightforward code is what everyone wanted, and I finally caved. Now I use braces and semicolons and parentheses everywhere they can legally go. I no longer pay attention to operator precedence: Parens make that a non-issue in all but a very few cases. I no longer ever have "if" and "else" on the same line, and always have full brace sets between them.
I no longer define structs and enums in-place, even when they are throw-aways. I use layer upon layer of typedefs to avoid the magic of tangled Gordian C type declarations. My include files are huge and comprehensive. I use variable names with more than one letter, sometimes they may even be found in dictionaries (of some language). Then I started using variable naming conventions, so all my pointers start with p, and member data with m, and so on to the land of the noted Hungarian.
Well, I did stop at that last one. Nipped it in the bud. I'm not that far gone. Not quite yet.
But then it got worse: I started using "style guides" and "coding standards". Then I even started writing the damned things! Then my code started to go through the pretty-printer/reformatter without even a single change. (BTW, "astyle" rocks.) I even started thinking the blasted tools "rocked". I started using lint and "-Wall", and my compiles became warning-free. Pffft. Warnings are feared only by those who don't know what they mean.
I had to enter so many more characters in my code that I actually had to stop looking at the keyboard while I typed. My comment-to-code ratio went from 1:10 to 2:1, and I even started using documentation generators (which would always gag on my old code). I had to go to ever-higher display resolutions on ever-larger displays to get enough code visible in a single window to hold a complete thought.
My functions had only a single entry and exit and were goto-free, with each loop fully closed, each if else'd.
Yes, I truly caved.
But I still sneak in the occasional line or two of raw distilled power-code. I am a man, dammit! And I can still code my way out of a paper bag. But I do it with about 20 lines of surrounding comments. (It feels like wrapping a diamond in burlap.)
My "safe" coding has had its cost: I no longer solve those PC-Lint puzzles in a single glance. Sometimes it takes two glances, taking a pause between them to adjust the reading glasses on my nose. I no longer "see" code in the empty editor window, like I did way back when, when the hardest problem was making my eyes keep up with my fingers on the keyboard. Now I actually have to do designs. And do eye exercises.
But at least my typing has improved. It allows me to write long, wandering posts to newsgroups in the blink of an eye.
I like D simply because it removes so much of the temptation to delve into obfuscation. The only problem is that I have to fire up a Windows system to use it.
Did I mention I'm really good on the keyboard? I hate mice. I hate windowing systems that don't have keystrokes for doing everything. I hate MS Windows. I hate that D runs only under Windows. I hate that I have to take down my ultra-stable SMP Linux system, and reboot into Win98 (and give up a processor) to run D.
But it is worth it, once in a while, if only so I can avoid the seductive siren call of minimalist C.
Somebody shoot me.
-BobC
PS: D rocks!
|
June 11, 2002 Re: enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert W. Cunningham | Bob If you were an attractive lady, and I not unattached to mine, I think I'd have to marry you! Almost completely agree with everything you say, particularly salient is your description of the maturation process from hero-geek to software engineer. I'm always bemused when people have not made that transition after many years in the game. Surely it's either that they've been working on the same product/project, for the same company, using the same technology. Like you, once reviewing and teaching became a large part of what I do, the use of all those neat tricks (that still appeal, as you say) becomes untenable. How can one say "you must do x" when one is still doing "!x". Down with hypocrisy, down with short-term solutions (minimal coding now for maximum maintenance in the future). One of the _few_ good things about Java is that the compiler enforces a few good things (missing / superfluous exception catches, boolean conditional statements, etc.) on the practise of its programmers. On thge subject of Hungarianism, always making conditional expressions boolean aids with reducing the amount of Hungarian. In addition, by forcing pointers/references to compare to null (rather than 0) also assists. Pretty much only use p and cch/cb (differentiation between count of characters and count of bytes is very important in Ansi/Unicode C/C++) these days. Matthew P.S. Agree D rocks, but there's a lot more stuff needed until it blasts the hell out of Java and C# (I know Walter doesn't see it as a competitor for these languages, rather as an evolution of C++, but that's exactly what I see as its most important (from a political point of view) target). "Robert W. Cunningham" <rcunning@acm.org> wrote in message news:3D056A53.CAC0C830@acm.org... > Matthew Wilson wrote: > > > And a very good thing too. Now if we can wean all the terse programmers away > > from all their other write-once unmaintain-ever-more practises, we should > > really be cooking > > Reminds me of my own torrid programming past. As a deeply-embedded C programmer for 20 years now, one who was brought up on assembler, I still have > this craven need to write monstrously complex functions in two or three lines > of impenetrable obfuscated C. The goal is to do the most with the fewest keystrokes, yet make the fastest possible code. > > My peers hated it. My bosses hated it. When I became independent, my clients > hated it. But you see, sometimes I just had to do it. I couldn't resist. I > want to push C down to the level of finely honed assembly macros (which can get > positively Forth-like if left to their own devices). And if the rest of the > world couldn't understand it, well, it just proved they didn't really know C > all that well. Right? > > To make everyone shut up, I started putting the "correct" code in there as well, then I'd use the preprocessor to switch between the two instances. I > could show the two were functionally equivalent (and on some occasions they > even produced the same code). > > Well, compilers got smarter, the style battles got harder to fight, and programmers got dumber (in a good way ;^). Simple straightforward code is what > everyone wanted, and I finally caved. Now I use braces and semicolons and parentheses everywhere they can legally go. I no longer pay attention to operator precedence: Parens make that a non-issue in all but a very few cases. I no longer ever have "if" and "else" on the same line, and always have > full brace sets between them. > > I no longer define structs and enums in-place, even when they are throw-aways. > I use layer upon layer of typedefs to avoid the magic of tangled Gordian C type > declarations. My include files are huge and comprehensive. I use variable > names with more than one letter, sometimes they may even be found in dictionaries (of some language). Then I started using variable naming conventions, so all my pointers start with p, and member data with m, and so on > to the land of the noted Hungarian. > > Well, I did stop at that last one. Nipped it in the bud. I'm not that far > gone. Not quite yet. > > But then it got worse: I started using "style guides" and "coding standards". > Then I even started writing the damned things! Then my code started to go through the pretty-printer/reformatter without even a single change. (BTW, > "astyle" rocks.) I even started thinking the blasted tools "rocked". I started using lint and "-Wall", and my compiles became warning-free. Pffft. > Warnings are feared only by those who don't know what they mean. > > I had to enter so many more characters in my code that I actually had to stop > looking at the keyboard while I typed. My comment-to-code ratio went from 1:10 > to 2:1, and I even started using documentation generators (which would always > gag on my old code). I had to go to ever-higher display resolutions on ever-larger displays to get enough code visible in a single window to hold a > complete thought. > > My functions had only a single entry and exit and were goto-free, with each > loop fully closed, each if else'd. > > Yes, I truly caved. > > But I still sneak in the occasional line or two of raw distilled power-code. I > am a man, dammit! And I can still code my way out of a paper bag. But I do it > with about 20 lines of surrounding comments. (It feels like wrapping a diamond > in burlap.) > > My "safe" coding has had its cost: I no longer solve those PC-Lint puzzles in > a single glance. Sometimes it takes two glances, taking a pause between them > to adjust the reading glasses on my nose. I no longer "see" code in the empty > editor window, like I did way back when, when the hardest problem was making my > eyes keep up with my fingers on the keyboard. Now I actually have to do designs. And do eye exercises. > > But at least my typing has improved. It allows me to write long, wandering > posts to newsgroups in the blink of an eye. > > I like D simply because it removes so much of the temptation to delve into obfuscation. The only problem is that I have to fire up a Windows system to > use it. > > Did I mention I'm really good on the keyboard? I hate mice. I hate windowing > systems that don't have keystrokes for doing everything. I hate MS Windows. I > hate that D runs only under Windows. I hate that I have to take down my ultra-stable SMP Linux system, and reboot into Win98 (and give up a processor) > to run D. > > But it is worth it, once in a while, if only so I can avoid the seductive siren > call of minimalist C. > > Somebody shoot me. > > > -BobC > > PS: D rocks! > > |
June 11, 2002 Re: enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | It just seems kludgy; It's the behavior I'd want from enums to begin with. But that may be just because I come from a C++ background where enums do work like this. In fact to be perfectly compatible with C++ enum, it'd have to be completely rewritten: instead of : // in C++ enum Colors { red, green, blue }; // in D typedef uint Colors; public const Colors red = Colors(0); public const Colors green = Colors(1); public const Colors blue = Colors(2); Now that sucks. Sean "Pavel Minayev" <evilone@omen.ru> wrote in message news:ae34ko$l9e$1@digitaldaemon.com... > "Sean L. Palmer" <seanpalmer@earthlink.net> wrote in message news:adu3qg$1hsh$1@digitaldaemon.com... > > > What I want is an anonymous enum with a name, evidently. ;) > > Just make an alias: > > alias int OLD_C_ENUM; > enum { ... } > > This worked fine for me. =) |
June 11, 2002 Re: enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | "Sean L. Palmer" <seanpalmer@earthlink.net> wrote in message news:ae41t3$1i6q$1@digitaldaemon.com... > It just seems kludgy; It's the behavior I'd want from enums to begin with. > But that may be just because I come from a C++ background where enums do work like this. > > In fact to be perfectly compatible with C++ enum, it'd have to be completely > rewritten: > > instead of : > > // in C++ > > enum Colors { red, green, blue }; > > // in D > > typedef uint Colors; > public const Colors red = Colors(0); > public const Colors green = Colors(1); > public const Colors blue = Colors(2); Not necessary: typedef uint Colors; enum : Colors { red, green, blue }; note the colon. |
June 11, 2002 Re: enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert W. Cunningham | This is a great post! Thanks. -Walter |
June 11, 2002 Re: enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert W. Cunningham | "Robert W. Cunningham" <rcunning@acm.org> wrote in message news:3D056A53.CAC0C830@acm.org... > > Reminds me of my own torrid programming past. As a deeply-embedded C programmer for 20 years now, one who was brought up on assembler, I still have > this craven need to write monstrously complex functions in two or three lines > of impenetrable obfuscated C. The goal is to do the most with the fewest keystrokes, yet make the fastest possible code. > > [... big snip of an highly worth-to-read piece of text ...] I don't have enough skill in english to express how much I agree with you. I have only 14 years of programming and I don't make any embedded work, but my story is very similar to yours. I think your article should be published on the web for everyone to read. Ciao |
June 11, 2002 Re: enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to Roberto Mariottini | Roberto That's an excellent idea. Bob, do you fancy having that post as an opinion piece in the first issue of "The D Journal"? "Roberto Mariottini" <rmariottini@lycosmail.com> wrote in message news:ae4mpp$27vo$1@digitaldaemon.com... > > "Robert W. Cunningham" <rcunning@acm.org> wrote in message news:3D056A53.CAC0C830@acm.org... > > > > Reminds me of my own torrid programming past. As a deeply-embedded C programmer for 20 years now, one who was brought up on assembler, I still > have > > this craven need to write monstrously complex functions in two or three > lines > > of impenetrable obfuscated C. The goal is to do the most with the fewest > > keystrokes, yet make the fastest possible code. > > > > [... big snip of an highly worth-to-read piece of text ...] > > I don't have enough skill in english to express how much I agree with you. > I have only 14 years of programming and I don't make any embedded > work, but my story is very similar to yours. > > I think your article should be published on the web for everyone to read. > > Ciao > > |
June 11, 2002 Re: enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <walter@digitalmars.com> wrote in message news:ae47lc$1p4a$1@digitaldaemon.com... > > In fact to be perfectly compatible with C++ enum, it'd have to be completely rewritten: > > > > instead of : > > > > // in C++ > > > > enum Colors { red, green, blue }; > > > > // in D > > > > typedef uint Colors; > > public const Colors red = Colors(0); > > public const Colors green = Colors(1); > > public const Colors blue = Colors(2); > > Not necessary: > > typedef uint Colors; > enum : Colors { red, green, blue }; > > note the colon. What does the colon do, again? |
June 11, 2002 Re: enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | "Sean L. Palmer" wrote: > "Walter" <walter@digitalmars.com> wrote in message news:ae47lc$1p4a$1@digitaldaemon.com... > > > In fact to be perfectly compatible with C++ enum, it'd have to be > completely rewritten: > > > > > > instead of : > > > > > > // in C++ > > > > > > enum Colors { red, green, blue }; > > > > > > // in D > > > > > > typedef uint Colors; > > > public const Colors red = Colors(0); > > > public const Colors green = Colors(1); > > > public const Colors blue = Colors(2); > > > > Not necessary: > > > > typedef uint Colors; > > enum : Colors { red, green, blue }; > > > > note the colon. > > What does the colon do, again? It defines the underlying type of the enum, rather than letting the compiler select it. -- The Villagers are Online! villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ] |
June 12, 2002 Re: enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew Wilson | <blush!>
Once in a while the muse strikes. But like the lightning, I can't control it. I really do wish I had paid attention during the two writing classes I had to endure to get my degree. They were the only English classes I had to take in five years of higher education.
Sure, use the post however you like! But don't ask me to edit it: I'll kill it dead, since my normal writing style is third-person-distant.
But please keep the headers with it: Context is important, and I hope it will encourage people to read the other fantastic threads that keep appearing in this newsgroup.
As several others have noted before, this is one hell of a special group. And I'm delighted that it has kept its flavor and quality as the D crowd has grown. I doubt I'd have ever thought to toss my random thoughts into any other forum. That is, I probably wouldn't even have thought the thoughts I wrote.
This place seems to make people think deeper and write better. Many members of this forum entered with sirens howling, strobes flashing, and guns blazing. Then, within a week or a month, each would calm down, listen, then start to contribute in a big way. Tolerance, understanding and persistence are rare things to be expressed so well, and so often.
This place rocks.
-BobC
PS: What if we got the Israelis and Palestinians to sit down and learn D? We'd probably see the first peace treaty that compiled without error, ran without crashing, and was understood by everyone to be the correct solution to the problem. ;^)
Matthew Wilson wrote:
> Roberto
>
> That's an excellent idea.
>
> Bob, do you fancy having that post as an opinion piece in the first issue of "The D Journal"?
>
> "Roberto Mariottini" <rmariottini@lycosmail.com> wrote in message news:ae4mpp$27vo$1@digitaldaemon.com...
> >
> > "Robert W. Cunningham" <rcunning@acm.org> wrote in message news:3D056A53.CAC0C830@acm.org...
> > >
> > > Reminds me of my own torrid programming past. As a deeply-embedded C programmer for 20 years now, one who was brought up on assembler, I
> still
> > have
> > > this craven need to write monstrously complex functions in two or three
> > lines
> > > of impenetrable obfuscated C. The goal is to do the most with the
> fewest
> > > keystrokes, yet make the fastest possible code.
> > >
> > > [... big snip of an highly worth-to-read piece of text ...]
> >
> > I don't have enough skill in english to express how much I agree with you.
> > I have only 14 years of programming and I don't make any embedded
> > work, but my story is very similar to yours.
> >
> > I think your article should be published on the web for everyone to read.
> >
> > Ciao
> >
> >
|
Copyright © 1999-2021 by the D Language Foundation