473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Programming style section from Josuttis' C++ template book

KPB

I have an O'Reilly Safari Online subscription. I decided to check out
this book(C++ Templates) and am half way through it.

For those of you who read this one, I don't know what you thought about
section 1.4 (Some remarks about Programming Style) but I thought it was
weird at first.

You know? Writing an init statement like this:

int const N = 100;

instead of like this (which I've always done)

const int N = 100;
I have to say though, the style outlined in the book has really grown on
me. It really makes sense when you throw a reference token or pointer
token in there. Just read it from right to left

char const* const p = 0;

I know from reading this right to left it's a "constant pointer" to a
"constant character".

Using this way as I always have done:

const char* const p = 0;

I always had to think about it for a second.

I see the authors' points about this. Did any of you are do you still
think it's *weird*?

Just curious.

KPB
Jul 22 '05 #1
7 1514
KPB wrote:
[...]
int const N = 100;

instead of like this (which I've always done)

const int N = 100;

I have to say though, the style outlined in the book has really
grown on me. It really makes sense when you throw a reference
token or pointer token in there. Just read it from right to left
[...]
I see the authors' points about this. Did any of you are do you
still think it's *weird*?


I find it makes declarations harder to read "at a glance", but easier
to untangle when I have to read them one step at a time. If English
were not my native language, I might find (char const *) more natural,
but in English, I am used to adjectives coming first.

I've found that I prefer the style from the book, and I experimented
with it in a small tool I wrote, and it's not hard to get used to. I'm
unsure I would use it in real code, though.

--
Dave O'Hearn

Jul 22 '05 #2
KPB
Dave O'Hearn wrote:
KPB wrote: I've found that I prefer the style from the book, and I experimented
with it in a small tool I wrote, and it's not hard to get used to. I'm
unsure I would use it in real code, though.


I feel the same way. Not sure if I'll start using this at work myself.

When I first read this, I was thinking "This is bullshit details! Let's
get to the good stuff!" I hadn't realized how cool this little detail was.

Yes.. the rest of the book is great too so far. :-)

Jul 22 '05 #3
KPB,

Yes, it took me a while to recalibrate to this small shift of putting the
const after the type. The section of 1.4 in that book on syntactical
substitution principle was quite interesting in that it shows a case where
putting the const *before* the type can actually cause confusion if someone
thinks you can just textually replace a typedef.

Also in favor of putting the const after the type it modifies is that is how
compilers view it so if you wrote a function void func(const char* p), and
then viewed the symbols generated by the compiler using what every binary
utils are available for your compiler, you will see that the compiler thinks
of that function as void func(char const* p). Can be usesful to think this
way to decipher compiler error messages. Matter of taste of course but
interesting to view if both ways.

Regards,
Bruce
"KPB" <kw@foo.net> wrote in message news:At***************@fe11.lga...

I have an O'Reilly Safari Online subscription. I decided to check out
this book(C++ Templates) and am half way through it.

For those of you who read this one, I don't know what you thought about
section 1.4 (Some remarks about Programming Style) but I thought it was
weird at first.

You know? Writing an init statement like this:

int const N = 100;

instead of like this (which I've always done)

const int N = 100;
I have to say though, the style outlined in the book has really grown on
me. It really makes sense when you throw a reference token or pointer
token in there. Just read it from right to left

char const* const p = 0;

I know from reading this right to left it's a "constant pointer" to a
"constant character".

Using this way as I always have done:

const char* const p = 0;

I always had to think about it for a second.

I see the authors' points about this. Did any of you are do you still
think it's *weird*?

Just curious.

KPB

Jul 22 '05 #4
KPB
Bruce Trask wrote:
The section of 1.4 in that book on syntactical
substitution principle was quite interesting in that it shows a case where
putting the const *before* the type can actually cause confusion if someone
thinks you can just textually replace a typedef.


Actually, I think I experienced a similar typedef problem at work.
However, I was an hour away from Xmas vacation so didn't pay much
attention to it. I'll have to look at it again when I get back.

BTW, ... BAE Greenlawn?

Thanks,
KPB
Jul 22 '05 #5
KPB,
The section of 1.4 in that book on syntactical
substitution principle was quite interesting in that it shows a case where putting the const *before* the type can actually cause confusion if someone thinks you can just textually replace a typedef.
Actually, I think I experienced a similar typedef problem at work.
However, I was an hour away from Xmas vacation so didn't pay much
attention to it. I'll have to look at it again when I get back.


Right, at first I thought I groked that section fully but really had to work
some examples until I got it.
BTW, ... BAE Greenlawn?

Greenlawn and Wayne NJ. Mostly Wayne.

Regards,
Bruce Thanks,
KPB

Jul 22 '05 #6
Bruce Trask wrote:
BTW, ... BAE Greenlawn?

Greenlawn and Wayne NJ. Mostly Wayne.


Ever run across a fellow named Mike Yackavage in Greenlawn?

--
Mike Smith
Jul 22 '05 #7

"Mike Smith" <mi*******************@acm.DOT.org> wrote in message
news:10*************@news.supernews.com...
Bruce Trask wrote:
BTW, ... BAE Greenlawn?

Greenlawn and Wayne NJ. Mostly Wayne.


Ever run across a fellow named Mike Yackavage in Greenlawn?


Please take personal conversations to email. Thanks.

-Mike
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

52
by: Tony Marston | last post by:
Several months ago I started a thread with the title "What is/is not considered to be good OO programming" which started a long and interesting discussion. I have condensed the arguments into a...
4
by: Hans-Christian Stadler | last post by:
Does Visual C++ Standard Edition support PCSC programming? Look after a file called WINSCARD.H in the system include directory of Visual Studio Standard Edition. If it's there, PCSC programming is...
0
by: TechBookReport | last post by:
The following is an extract of a review of the book 'Programming C#' by Jesse Libety and published by O'Reilly. The review is from TechBookReport (http://www.techbookreport.com): Jesse Liberty's...
1
by: SK | last post by:
Hi all, I have a doubt in C++ Templates by Nicolai M. Josuttis. On Page 17 there is a line "In general, it is a good idea not to change more than necessary when overloading function templates....
1
by: lallous | last post by:
Hello @ Page 48, the sample util/autoptr1.cpp: /* The following code example is taken from the book * "The C++ Standard Library - A Tutorial and Reference" * by Nicolai M. Josuttis,...
18
by: Exits Funnel | last post by:
Hello, I'm a little confused about where I should include header files and was wondering whether there was some convention. Imagine I've written a class foo and put the definition in foo.h and...
32
by: cat_dog_ass | last post by:
I am used to programming in DOS mode via Borland C++. I would now like to create programs for the Windows envirinment. Is it absoultely necessary to use Visual C++ to do this? Are there other tools...
15
by: Earl Higgins | last post by:
The company where I work as a Senior Software Engineer is currently revamping their (1991 era) "Programming and Style Guidelines", and I'm on the committee. The company, in business for over 20...
3
by: Squirrel Havoc | last post by:
I am starting to write an FTP server, but I don't understand the PASV protocol. RFC's haven't been much help, since they don't describe what it is, or how it's done. Just what it can do (I think...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.