int main(void) is better than int main()

J

James Kanze

That's a fine answer. But not the end-all. I can think of many times
where the format is very context-specific. Where sometimes hex is 2
hexits, 4 hexits, 8 hexits, etc. But Your answer could work here too.

Exactly. For something rather general, like HexFmt, I'd
probably leave the first parameter, which specifies the number
of digits. But I wouldn't necessarily leave the second, which
in HexFmt allows adding any flags you might want.
Where do you reset the stream's settings? Or do they get left
in "whatever was last" state?

I reset them in the destructor. Since the object is always a
temporary, it gets destructed at the end of the full expression.
but it really doesn't take long to master 90% of the useful
features of it. Don't make it sound harder than it is.

Experience has shown me that most C programmers, even
experienced ones, only know about 10% of it.

It works well for debugging output, where you're not too
concerned with the format: almost everyone does retain that %d
outputs integers, %x does the same but in hex, and %f is for
fixed point. Most programmers quickly assimulate the x.y for
width and precision. Almost no one knows much about the
flags---note that one of the respondants here wondered why you
used octal in "%#08x" (Which, of course, isn't octal. The 0 is a
flag, and not part of the numeric value. Which can't be octal:
even in "%20.010f", the precision is 10, and not 8.)
Again, I'd never advocate printf() proper, when typesafe
alternatives are available. And boost::format DOES work with
user defined types.

Yes. Under the hood, boost::format uses ostream. *All* it
does, in fact, is set formatting flags. (I had a discussion
with the author in one of the forums at one point. I believe
that one of his goals was that formatting specifiers would only
affect the flags. In my case, in Gabi::Format (or GB_Format, as
it was back then---this was long before namespaces, or even
templates), someone challenged me to attain 100% compatibility,
so I did. Which meant intercepting some of the types (integral,
floating point, etc.) and doing some extra formatting by hand; I
then extracted this logic so that it would be easy to provide it
for user defined numeric types.

Quite frankly, the author of boost::format made the right
decision here. Well over half of my code was there to handle
special cases involving flags which 99% of the programmers have
never heard of. (On the other hand, the use of the % operator
for streaming is a disaster with regards to program
readability.)
Also, you're mentioned specifically in the boost::format docs,
which I did not realize until yesterday :)
I guess we'll just agree to do things differently. I am very
comfortable with printf() style formatters, and can read them
almost as quickly as plain code.

I'm very comfortable with them as well, having actually
implemented printf in the past, but most of my collegues aren't.
And of course, it still means specifying physical formatting
directly at the site of the output, which is a maintenance
nightmare.
I know how to use them when I need them, and they express the
vas majority of what I need to output. I find boost::format
to be a very useful tool when I need to do formatted IO very
simply.
When I have a custom type, I almost always add a
operator<<(ostream), and when appropriate I make it check the
flags on the stream for it's formatting. Thus, it works with
boost::format or ostream directly.
Lastly, I admit to being a C programmer still learning C++.
Iostreams do feel weird to me (I really liked Java's
to_string() model, iostreams is similar but inside out).

If it wasn't implicit, I'd go with the Java model as well.
Although both it and ostream have the disadvantage of cutting up
the output text into small bits and pieces, which causes
troubles for the translator. I've not looked at it lately, but
boost::format does support a simpler form of the format
specifier (i.e. "id = %1%, value = %2%"), and allows
manipulators, so you may be able to get the best of both worlds.
Provided they change the '%', of course. (I sort of like
something like:
Format( "%1%: %2%" ).with( id ).with( value )
But you'd not want a separate "with()" for the manipulators;
something like:
Format( "%1%: %2%" ).with( id, 3 ).with( HexFmt( 8 ), value ) ;
would be more like it.

Maybe I should go back and see what I can do with my old code,
incorporating ideas from Boost. (My code did allow specifying
width and precision in three different ways: as a constant in
the format specifier, like printf; as an additional "argument",
by specifying a "*" in the format specifier, again like printf;
or as a second or third argument to with() (if you were using
with(), instead of <<---my code supported both). Or just grab
the Boost code, and add support for with()---it seems to do
everything I want, except allow a readable format in the
expression using it.
 
L

LR

James said:
It works well for debugging output, where you're not too
concerned with the format: almost everyone does retain that %d
outputs integers, %x does the same but in hex, and %f is for
fixed point. Most programmers quickly assimulate the x.y for
width and precision. Almost no one knows much about the
flags---note that one of the respondants here wondered why you
used octal in "%#08x" (Which, of course, isn't octal. The 0 is a
flag, and not part of the numeric value. Which can't be octal:
even in "%20.010f", the precision is 10, and not 8.)

I seem to have missed the post where someone wondered about the use of
octal in "%#08x". Could you please point out which post that is?

LR
 
T

Tim H

Exactly. For something rather general, like HexFmt, I'd
probably leave the first parameter, which specifies the number
of digits. But I wouldn't necessarily leave the second, which
in HexFmt allows adding any flags you might want.


I reset them in the destructor. Since the object is always a
temporary, it gets destructed at the end of the full expression.

Can you point me at example code of your formatters? I'm not saying
you'll make a convert out of me, but I'll try it.
with(), instead of <<---my code supported both). Or just grab
the Boost code, and add support for with()---it seems to do
everything I want, except allow a readable format in the
expression using it.

Can you add %* support, while you're in there? :)

Tim
 
B

Bill - Cincinnati, OH USA

We posted this message in order to 'stimulate' discussion over a topic
that is often misunderstood. It worked. I challenged my class to post
this topic, then sit back to see what happened. Thanks for playing
along.
 
R

red floyd

We posted this message in order to 'stimulate' discussion over a topic
that is often misunderstood. It worked. I challenged my class to post
this topic, then sit back to see what happened. Thanks for playing
along.
And how much are you going to pay us to be your teaching assistants?
 
B

Bill - Cincinnati, OH USA

"stunt" is your definition. "Learning Experience" would be more
appropriate.
 
R

red floyd

"stunt" is your definition. "Learning Experience" would be more
appropriate.

1. Please don't top-post (corrected)/
2. Fine, jerk. Read the FAQ before trying this "Learning Experience"
again.

*PLONK*
 
L

Lars Uffmann

[..bullcrap..]

Don't feed the trolls. Nothing to see here, move along please.

....

PS: Why do people believe this attention-whore to begin with? He is
probably lying, and even if not, no one should care, because the debate
wasn't directed at the stupid original poster, and this troll here
probably didn't even understand a fraction of it
 
L

Lionel B

We posted this message in order to 'stimulate' discussion over a topic
that is often misunderstood. It worked. I challenged my class to post
this topic, then sit back to see what happened. Thanks for playing
along.

Are you serious (I suspect not)? What's the course? "Trolling for Fun and
Profit", perhaps, to be taken along with "Spamming (Intermediate)" and
"An Introduction to Basic Trojan Architectures"?

Please supply the name of your educational establsihment so that we may
report you to your superiors for encouraging Usenet abuse.

Thanks,
 
J

Jim Langston

We posted this message in order to 'stimulate' discussion over a topic
that is often misunderstood. It worked. I challenged my class to post
this topic, then sit back to see what happened. Thanks for playing
along.

My accusation, then, of them being a troll was correct. Maybe you should
learn what a troll is.
 
E

Erik Wikström

On 2008-01-10 00:19, Bill - Cincinnati, OH USA wrote:

Please do not top-post (fixed).
Exactly what you are worth.

Nice, how do we arrange the payment?
 
B

Bill - Cincinnati, OH USA

I am indeed serious. You can suspect whatever you wish. I have a BS in
Engineering and an MS in Computer Science. I've been teaching for 15
years. I've written more lines of C/C++ than you ever will. I am not a
troll, nor am I abusing Usenet. We posted a serious message and people
commented on it. The thread went in several different directions and
brought up a number of interesting points.
We done good.

I encouraged the activity and one of my students was enterprising
enough to pursue the suggestion. We all learned something. Well,
almost all of us. People like you chose to stoop to name-calling and
hand-wringing. I don't know why -- I don't teach abnormal psychology.

Come down off your high horse and wade around in the real world with
the rest of us.
 
L

LR

Bill - Cincinnati, OH USA wrote:

You are top posting. In this group, top posting is frowned on. I would
like to know if that speaks to how serious you are?

I am indeed serious. You can suspect whatever you wish. I have a BS in
Engineering and an MS in Computer Science. I've been teaching for 15
years.

If this is true, and you really are serious, then please post from the
email account you've been given by the educational institution at which
you are employed. And if you don't, then why don't you?

I've written more lines of C/C++ than you ever will.

How do you know that? And how are you able to predict what will happen
in the future?

C/C++? Oh. I see.

I am not a troll, nor am I abusing Usenet.

Perhaps not. But it seems that you've made a bad impression.

> We posted a serious message

From my perspective, the subject, and particularly the way it is
phrased indicate that it is not a serious post.

But perhaps I'm wrong. What was your serious intent? I'm curious.



and people
commented on it. The thread went in several different directions and
brought up a number of interesting points.

One of which was that several regular posters suspect your intentions.

We done good.

Aside from the ambiguity in that statement, I suggest that this claim is
being debated. Coming from someone who claims to be an academic, the
assertion is interesting in and of itself, but at least a few people
here seem to have expressed their disagreement with your opinion.

I encouraged the activity

I for one would like to know why.

and one of my students was enterprising
enough to pursue the suggestion.

Enterprising? May I ask what the title of the course you're teaching is?

We all learned something. Well, almost all of us.

I suppose that depends on how you define 'we' and what you think
might've been learned.
People like you chose to stoop to name-calling and
hand-wringing. I don't know why -- I don't teach abnormal psychology.

No? What is it that you teach then?

There are various reasons why people here take issue with the sort of
post one of your students made and with the reasons you give for it. I
strongly suspect that lurking here for a while before the post was made
would have made it clear why and also made clear what sort of reception
you might have gotten.
Come down off your high horse and wade around in the real world with
the rest of us.

Thanks.

LR
 
L

Lionel B

On Mon, 14 Jan 2008 09:20:50 -0800, Bill - Cincinnati, OH USA wrote:

(please don't top-post in this ng - rearranged)
I am indeed serious. You can suspect whatever you wish. I have a BS in
Engineering and an MS in Computer Science.

Great. I have an MS in mathematics and a PhD in Computer Science, so nyah
nyah nyah ;-)
I've been teaching for 15 years. I've written more lines of C/C++
than you ever will.

I wouldn't bet on it.
I am not a troll, nor am I abusing Usenet.
Debatable.

We posted a serious message and people commented on it.

The original message did not come across as "serious"; rather, it came
across as a deliberately provocative, unsubstantiated assertion - i.e.
trollish. That is not the style of this ng and was likely to be regarded
with suspicion here - as some cursory browsing would have revealed.
The thread went in several different directions and
brought up a number of interesting points.

It did - thanks to the generally high quality of debate here - *despite*
the tone of the original post.

If your original post had (a) been upfront about its motivation (why was
it not?) and (b) had a less provocative subject, I wouldn't have had a
problem with it. E.g.

Subject: Use of "int main(void)" as opposed to "int main()"?

Body: "As part of a teaching exercise we would appreciate this ng's views
on the above topic".

If you really felt confident that this was a valid and respectable
exercise you might also have mentioned (or at least posted from an email
address of) your educational institution.
We done good.
hmmm...

I encouraged the activity and one of my students was enterprising
enough to pursue the suggestion. We all learned something. Well, almost
all of us. People like you chose to stoop to name-calling and
hand-wringing. I don't know why

Because - and to be charitable I'm prepared to put it down to naivety
regarding Usenet etiquette - your post came across (to myself, and
evidently to others too) as a troll.
-- I don't teach abnormal psychology.

Come down off your high horse and wade around in the real world with
the rest of us.

I'm wading, I'm wading...
^^^^^^^^
(please don't post signatures)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top