Man.. i've been sitting here all day thinking how dumb those people were that screwed up their code cos they didn't preview , and then I do it myself:) Mods mod down my previous to 0..
Here's take 2: the bad template coder's Hello World
template <char a, char b, char c = 'l', char d = 'o'> void print_hello_world(void) { printf("%c%c%c%c%c w%cr%cd\n", a, b, c, c, d, d, c); }
int main(void) { print_hello_world<'h', 'e'>(); return 0; }
and as long as you remember to not actually include foo.cpp in your project file / makefile !
If I were to put the implementation separate from the class definition, I'd rather it were in a file with extension other than.cpp (or at least, ssomething like.template.cpp)
Working in an environment where I often have to code an application in C for an embedded environment, then code the same application in C++ in Windows, I invariably do the C++ 'from scratch', using C++ features and the Windows API.
Presumably, you are the sort of person who does not know that much about what goes on 'under the hood' in C++ (therefore, a bad C++ programmer)... look up 'name mangling' next time you read a C++ manual.
I'm worried by the reviewer's comment that there are no examples. I hate that stupid backas-naur crap. Can you elaborate more on the books' general technique (how it introduces a topic and how it illustrates it).
Why does the former approach require you to inspect their function?
All they have to do is look at the compiler message and make sure their object has the relevant operators. After all, if an object is unable to compare itself to others, or print itself on ostream, then it is not suitable for your stated purposes anyway !
The template method is way better than the derived class method, if you ever need to change something in your code later in time, or port the code elsewhere. Not to mention how inflexible this would be if it were code destined for a library.
I do lots of C++ programming but never use the STL. The reason for this is that I have never seen a tutorial for it that doesn't completely suck. Can you recommend any?
Yes you're right, although you should have spelled it out more that you meant code size bloat, not slowness, as there seem to be a whole bunch of people saying their template code runs fast:)
These days, runtime speed and reducing development time are more important than file size, it seems.
Well said. Let's not also forget that the template parameters don't have to be data types, for example they can be the bounds of some sort of collection - or even a flag for some function/class that looks much more elegant that #if.. #elif... everywhere
If you're writing production code then you don't want weird exceptions throwing up all over the place. I'd far rather make the straitjacket I want and then keep to it, than have a higher risk of my program barfing.
For example, with the Stack cast to int before - what if the stack definition is somewhere over the other part of the program, and one member of the team decides it should be a stack of vectors (or something), and your code to pop an int is in a very rare situation (so it may get missed in blackbox testing) ?
There are consumer protection laws requiring companies to provide products that aren't defective. I think you could mount a case under this, forcing the manufacturer to provide parts.
Have you got a parent page for this so I can look up other countries? (The link on that page "Return to Country Analysis Briefs Home Page" seems to point to V:\PRJ\CABSLAN\contents.html)
I looked at one of his source files once and it was full of functions with one-letter names, which contained variables with one-letter names. By 'good' I presume you mean 'runs without bugs', not the usual meaning of 'good code'.
Man.. i've been sitting here all day thinking how dumb those people were that screwed up their code cos they didn't preview , and then I do it myself :) Mods mod down my previous to 0..
Here's take 2: the bad template coder's Hello World
template <char a, char b, char c = 'l', char d = 'o'> void print_hello_world(void)
{
printf("%c%c%c%c%c w%cr%cd\n", a, b, c, c, d, d, c);
}
int main(void)
{
print_hello_world<'h', 'e'>();
return 0;
}
and as long as you remember to not actually include foo.cpp in your project file / makefile !
.cpp (or at least, ssomething like .template.cpp)
If I were to put the implementation separate from the class definition, I'd rather it were in a file with extension other than
template void print_hello_world(void)
{
printf("%c%c%c%c%c w%cr%cd\n", a, b, c, c, d, d, c);
}
int main(void)
{
print_hello_world();
return 0;
}
Templates are safer than (void *) casts :)
Working in an environment where I often have to code an application in C for an embedded environment, then code the same application in C++ in Windows, I invariably do the C++ 'from scratch', using C++ features and the Windows API.
Presumably, you are the sort of person who does not know that much about what goes on 'under the hood' in C++ (therefore, a bad C++ programmer) ...
look up 'name mangling' next time you read a C++ manual.
I've never had any problem with Borland's compilation of templates. Have you given C++Builder a try instead of VC?
I'm worried by the reviewer's comment that there are no examples. I hate that stupid backas-naur crap. Can you elaborate more on the books' general technique (how it introduces a topic and how it illustrates it).
Why does the former approach require you to inspect their function?
All they have to do is look at the compiler message and make sure their object has the relevant operators. After all, if an object is unable to compare itself to others, or print itself on ostream, then it is not suitable for your stated purposes anyway !
The template method is way better than the derived class method, if you ever need to change something in your code later in time, or port the code elsewhere. Not to mention how inflexible this would be if it were code destined for a library.
I can program both C++ and QBasic. (There was a time when I did both). I did not go around writing C++ code like:
line_10: int i;
line_20: for (i = 1; i = 1000; i++)
if (str[i-1] == 'p')
puts("Found a p");
I do lots of C++ programming but never use the STL. The reason for this is that I have never seen a tutorial for it that doesn't completely suck. Can you recommend any?
Yes you're right, although you should have spelled it out more that you meant code size bloat, not slowness, as there seem to be a whole bunch of people saying their template code runs fast :)
These days, runtime speed and reducing development time are more important than file size, it seems.
Well said. Let's not also forget that the template parameters don't have to be data types, for example they can be the bounds of some sort of collection - or even a flag for some function/class that looks much more elegant that #if .. #elif ... everywhere
If you're writing production code then you don't want weird exceptions throwing up all over the place. I'd far rather make the straitjacket I want and then keep to it, than have a higher risk of my program barfing.
For example, with the Stack cast to int before - what if the stack definition is somewhere over the other part of the program, and one member of the team decides it should be a stack of vectors (or something), and your code to pop an int is in a very rare situation (so it may get missed in blackbox testing) ?
serious question - is it possible to have a Beowulf cluster of Beowulf clusters?
It's not meant to be a mnemonic, just a curiosity
You guys get free electricity over there?
There are consumer protection laws requiring companies to provide products that aren't defective. I think you could mount a case under this, forcing the manufacturer to provide parts.
Have you got a parent page for this so I can look up other countries? (The link on that page "Return to Country Analysis Briefs Home Page" seems to point to V:\PRJ\CABSLAN\contents.html)
Your theory would make sense, if the real version had actually been released (or was even still under development).
Does this take some of the sting out of the old insult "So, what ya gonna do for a face when the monkey wants his bum back?"
The story mentioned that SLAC has the biggest known database in the world - what's in this database and are there any pages about it?
Hey, I have that one
That reminds me of the time Microsoft called Sun unreliable because the box sometimes crashed when hot-swapping the motherboard
I looked at one of his source files once and it was full of functions with one-letter names, which contained variables with one-letter names. By 'good' I presume you mean 'runs without bugs', not the usual meaning of 'good code'.
Some of the contents of the repository:
- Inflatable dartboard
- Helicopter with ejector seat
- Waterproof towel
- Chocolate kettle
- Solar powered torch
- Pedal-powered wheelchair
- Submarine with window wipers
(No potatoes.)