Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #15924 > unrolled thread
| Started by | nroberts <roberts.noah@gmail.com> |
|---|---|
| First post | 2012-01-18 13:53 -0800 |
| Last post | 2012-02-01 21:55 +0000 |
| Articles | 20 on this page of 86 — 30 participants |
Back to article view | Back to comp.lang.c
Am I being too C++ like? nroberts <roberts.noah@gmail.com> - 2012-01-18 13:53 -0800
Re: Am I being too C++ like? Shao Miller <sha0.miller@gmail.com> - 2012-01-18 18:50 -0500
Re: Am I being too C++ like? Nobody <nobody@nowhere.com> - 2012-01-19 04:13 +0000
Re: Am I being too C++ like? ImpalerCore <jadill33@gmail.com> - 2012-01-19 09:09 -0800
Re: Am I being too C++ like? Philip Lantz <prl@canterey.us> - 2012-01-18 21:42 -0800
Re: Am I being too C++ like? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-01-19 12:30 +0000
Re: Am I being too C++ like? "BartC" <bc@freeuk.com> - 2012-01-19 15:17 +0000
Re: Am I being too C++ like? Keith Thompson <kst-u@mib.org> - 2012-01-19 18:44 -0800
Re: Am I being too C++ like? "BartC" <bc@freeuk.com> - 2012-01-20 13:44 +0000
Re: Am I being too C++ like? Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-01-20 09:08 -0500
Re: Am I being too C++ like? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-20 07:58 -0800
Re: Am I being too C++ like? Keith Thompson <kst-u@mib.org> - 2012-01-20 11:25 -0800
Re: Am I being too C++ like? Kleuske <kleuske@nowhere.net> - 2012-01-20 20:17 +0000
Re: Am I being too C++ like? Ian Collins <ian-news@hotmail.com> - 2012-01-21 09:23 +1300
Re: Am I being too C++ like? Kleuske <kleuske@nowhere.net> - 2012-01-20 22:00 +0000
Re: Am I being too C++ like? Stephen Sprunk <stephen@sprunk.org> - 2012-01-20 16:28 -0600
Re: Am I being too C++ like? Ian Collins <ian-news@hotmail.com> - 2012-01-21 11:43 +1300
Re: Am I being too C++ like? Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-01-20 18:02 -0500
Re: Am I being too C++ like? Keith Thompson <kst-u@mib.org> - 2012-01-20 16:12 -0800
Re: Am I being too C++ like? Kaz Kylheku <kaz@kylheku.com> - 2012-01-21 00:13 +0000
Re: Am I being too C++ like? William Ahern <william@wilbur.25thandClement.com> - 2012-01-20 17:37 -0800
Re: Am I being too C++ like? Keith Thompson <kst-u@mib.org> - 2012-01-20 22:25 -0800
Re: Am I being too C++ like? gazelle@shell.xmission.com (Kenny McCormack) - 2012-01-21 16:07 +0000
Re: Am I being too C++ like? Bill Reid <hormelfree@gmail.com> - 2012-01-23 17:26 -0800
Re: Am I being too C++ like? Kaz Kylheku <kaz@kylheku.com> - 2012-01-21 18:00 +0000
Re: Am I being too C++ like? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-21 21:25 +0000
Re: Am I being too C++ like? Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-02-11 23:46 +0200
Re: Am I being too C++ like? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-02-11 22:56 +0000
Re: Am I being too C++ like? Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-02-22 02:34 +0200
Re: Am I being too C++ like? Jens Gustedt <jens.gustedt@loria.fr> - 2012-01-21 22:42 +0100
Re: Am I being too C++ like? James Kuyper <jameskuyper@verizon.net> - 2012-01-21 21:22 -0500
Re: Am I being too C++ like? Jens Gustedt <jens.gustedt@loria.fr> - 2012-01-22 14:56 +0100
Re: Am I being too C++ like? Ian Collins <ian-news@hotmail.com> - 2012-01-22 10:29 +1300
Re: Am I being too C++ like? Kleuske <kleuske@nowhere.net> - 2012-01-21 11:36 +0000
Re: Am I being too C++ like? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-01-22 12:13 +0000
Re: Am I being too C++ like? Kleuske <kleuske@nowhere.net> - 2012-01-22 12:39 +0000
Re: Am I being too C++ like? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-01-23 23:45 +0000
Re: Am I being too C++ like? Kleuske <kleuske@nowhere.net> - 2012-01-24 16:54 +0000
Re: Am I being too C++ like? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-22 04:43 -0800
Re: Am I being too C++ like? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-22 15:29 +0000
Re: Am I being too C++ like? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-01-21 11:58 +0000
Re: Am I being too C++ like? Seebs <usenet-nospam@seebs.net> - 2012-01-21 21:32 +0000
Re: Am I being too C++ like? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-19 04:23 -0800
Re: Am I being too C++ like? Rui Maciel <rui.maciel@gmail.com> - 2012-01-19 14:39 +0000
Re: Am I being too C++ like? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-22 05:14 -0800
Re: Am I being too C++ like? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-01-23 23:42 +0000
Re: Am I being too C++ like? Rui Maciel <rui.maciel@gmail.com> - 2012-01-19 14:51 +0000
Re: Am I being too C++ like? jgk@panix.com (Joe keane) - 2012-01-19 23:04 +0000
Re: Am I being too C++ like? Ian Collins <ian-news@hotmail.com> - 2012-01-20 16:03 +1300
Re: Am I being too C++ like? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-20 06:01 -0800
Re: Am I being too C++ like? Ian Collins <ian-news@hotmail.com> - 2012-01-21 08:03 +1300
Re: Am I being too C++ like? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-21 12:31 -0800
Re: Am I being too C++ like? Ian Collins <ian-news@hotmail.com> - 2012-01-22 10:18 +1300
Re: Am I being too C++ like? cri@tiac.net (Richard Harter) - 2012-01-20 05:22 +0000
Re: Am I being too C++ like? Marco <prenom_nomus@yahoo.com> - 2012-01-21 07:29 -0800
Re: Am I being too C++ like? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-01-24 12:13 +0000
Re: Am I being too C++ like? Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-31 14:32 -0800
Re: Am I being too C++ like? Keith Thompson <kst-u@mib.org> - 2012-01-31 15:32 -0800
Re: Am I being too C++ like? Keith Thompson <kst-u@mib.org> - 2012-01-31 19:46 -0800
Re: Am I being too C++ like? Shao Miller <sha0.miller@gmail.com> - 2012-01-31 23:54 -0500
Re: Am I being too C++ like? Keith Thompson <kst-u@mib.org> - 2012-01-31 22:24 -0800
Re: Am I being too C++ like? Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-31 23:28 -0800
Re: Am I being too C++ like? Keith Thompson <kst-u@mib.org> - 2012-02-01 11:23 -0800
Re: Am I being too C++ like? Stephen Sprunk <stephen@sprunk.org> - 2012-02-01 15:01 -0600
Re: Am I being too C++ like? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-02-01 14:09 -0800
Re: Am I being too C++ like? Keith Thompson <kst-u@mib.org> - 2012-02-01 14:44 -0800
Re: Am I being too C++ like? Shao Miller <sha0.miller@gmail.com> - 2012-02-01 17:36 -0500
Re: Am I being too C++ like? Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-08 12:45 -0800
Re: Am I being too C++ like? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-03-08 21:41 +0000
Re: Am I being too C++ like? Ian Collins <ian-news@hotmail.com> - 2012-03-09 17:42 +1300
Re: Am I being too C++ like? Kaz Kylheku <kaz@kylheku.com> - 2012-03-09 08:12 +0000
Re: Am I being too C++ like? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-03-09 12:01 +0000
Re: Am I being too C++ like? Keith Thompson <kst-u@mib.org> - 2012-03-08 14:19 -0800
Re: Am I being too C++ like? Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-09 13:32 -0800
Re: Am I being too C++ like? nick_keighley_nospam@hotmail.com - 2012-03-09 04:18 -0800
Re: Am I being too C++ like? Ike Naar <ike@iceland.freeshell.org> - 2012-03-09 13:04 +0000
Re: Am I being too C++ like? Kaz Kylheku <kaz@kylheku.com> - 2012-03-10 01:02 +0000
Re: Am I being too C++ like? Ike Naar <ike@iceland.freeshell.org> - 2012-03-10 07:59 +0000
Re: Am I being too C++ like? Ian Collins <ian-news@hotmail.com> - 2012-03-10 21:17 +1300
Re: Am I being too C++ like? nick_keighley_nospam@hotmail.com - 2012-03-10 02:39 -0800
Re: Am I being too C++ like? Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-09 13:51 -0800
Re: Am I being too C++ like? nick_keighley_nospam@hotmail.com - 2012-03-10 02:54 -0800
Re: Am I being too C++ like? Ian Collins <ian-news@hotmail.com> - 2012-03-10 12:27 +1300
Re: Am I being too C++ like? Rui Maciel <rui.maciel@gmail.com> - 2012-02-01 07:41 +0000
Re: Am I being too C++ like? Keith Thompson <kst-u@mib.org> - 2012-02-01 11:24 -0800
Re: Am I being too C++ like? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-02-01 21:55 +0000
Page 3 of 5 — ← Prev page 1 2 [3] 4 5 Next page →
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Date | 2012-01-21 11:58 +0000 |
| Message-ID | <slrnjhla3f.1ls.grahn+nntp@frailea.sa.invalid> |
| In reply to | #15975 |
On Fri, 2012-01-20, BartC wrote: > "Keith Thompson" <kst-u@mib.org> wrote in message > news:lnfwfbxfcx.fsf@nuthaus.mib.org... >> "BartC" <bc@freeuk.com> writes: >>> "Jorgen Grahn" <grahn+nntp@snipabacken.se> wrote in message > >>>> I'd skip the typedef -- if something is a struct, I want to see >>>> that immediately. People typedef the weirdest things, so I feel I >>>> cannot assume such a name is a struct, and not a pointer or something. >>> >>> Couldn't you make exactly the same argument for *anything* defined with >>> typedef? >> >> Not quite. >> >> A typedef for a struct type just creates a new name (like "foo") for >> something that already has a name (like "struct foo"). It typically >> provides no new information, nor does it hide information that >> should be hidden; > > But if I create a new typedef T, and then declare: > > T a; > > I can't see at a glance whether T is a number, struct, and anything else. > That seemed to be the point of JG's remark. In this case it *does* hide some > information. I haven't followed your reasoning, and haven't yet read the followup postings. But the thing is: I avoid creating typedefs for /anything/ in C. I may use them as convenience aliases within a translation unit, but that's about it. (I use typedefs in C++ though, but they are more well-behaved there for various reasons.) /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o .
[toc] | [prev] | [next] | [standalone]
| From | Seebs <usenet-nospam@seebs.net> |
|---|---|
| Date | 2012-01-21 21:32 +0000 |
| Message-ID | <slrnjhma98.1nnu.usenet-nospam@guild.seebs.net> |
| In reply to | #15975 |
On 2012-01-20, BartC <bc@freeuk.com> wrote: > I can't see at a glance whether T is a number, struct, and anything else. > That seemed to be the point of JG's remark. In this case it *does* hide some > information. I usually consider this a bonus. :) -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions.
[toc] | [prev] | [next] | [standalone]
| From | Malcolm McLean <malcolm.mclean5@btinternet.com> |
|---|---|
| Date | 2012-01-19 04:23 -0800 |
| Message-ID | <b38b7e3c-da99-46e4-8dc5-9a5d2a76a41e@v14g2000vbc.googlegroups.com> |
| In reply to | #15924 |
On Jan 18, 9:53 pm, nroberts <roberts.n...@gmail.com> wrote:
> I keep getting told that what I write is more C++ like. I find it odd
> because I'm actually using C keywords I rarely if ever use in C++ like
> union. But two main examples come to mind:
>
> First, I use opaque types to encapsulate data so I can depend on the
> integrity of my structures. For example, when making a stack I had a
> header like so:
>
> struct stack;
> typedef struct stack Stack;
>
> Stack* createList();
> void* popFront(Stack*);
> void pushBack(Stack*);
>
>
In C, it's normal to hardcode simple structures like stacks. It's not
clear to me whether this is a strong point or a weak point of the
language, but it's generally easier to create a stack and stacktop
index with whatever structure you're pushing and popping than to mess
about with generic stack types. On feature is that your expression
parser, or whatever it is you are using the stack for, does not have a
dependency on a stack module.
>
> typedef struct base
> {
> int type;
> // shared data among all valid inputs
>
> } Base;
>
This is C++ implemented in C. Effectively what you are doing is
writing your own set of conventions for handling polymorphic data
types, and implementing them in C. Which means that C isn't the right
language for this approach. Sometimes it's necessary to use the wrong
language because of other considerations. However it should be a last
resort, and done sparingly.
[toc] | [prev] | [next] | [standalone]
| From | Rui Maciel <rui.maciel@gmail.com> |
|---|---|
| Date | 2012-01-19 14:39 +0000 |
| Message-ID | <jf99u8$eki$1@speranza.aioe.org> |
| In reply to | #15950 |
Malcolm McLean wrote: > In C, it's normal to hardcode simple structures like stacks. It's not > clear to me whether this is a strong point or a weak point of the > language, but it's generally easier to create a stack and stacktop > index with whatever structure you're pushing and popping than to mess > about with generic stack types. I believe it is a point where C is considerably weak. Better yet, it's a point where the C programming language could improve a great deal. If the C programming language supported function templates, even without supporting any form of template metaprogramming or non-type parameters, trully generic data structures would be possible without resorting to any coding voodoo. And this would be a good thing. Then again, if someone really requires templates and generic data structures then there is always C++. Rui Maciel
[toc] | [prev] | [next] | [standalone]
| From | Nick Keighley <nick_keighley_nospam@hotmail.com> |
|---|---|
| Date | 2012-01-22 05:14 -0800 |
| Message-ID | <77b2ed54-4b2c-4e60-8d3a-59aeffca1662@k29g2000vbl.googlegroups.com> |
| In reply to | #15950 |
On Jan 19, 12:23 pm, Malcolm McLean <malcolm.mcle...@btinternet.com>
wrote:
> On Jan 18, 9:53 pm, nroberts <roberts.n...@gmail.com> wrote:
> > I keep getting told that what I write is more C++ like. I find it odd
> > because I'm actually using C keywords I rarely if ever use in C++ like
> > union. But two main examples come to mind:
>
> > First, I use opaque types to encapsulate data so I can depend on the
> > integrity of my structures. For example, when making a stack I had a
> > header like so:
>
> > struct stack;
> > typedef struct stack Stack;
>
> > Stack* createList();
> > void* popFront(Stack*);
> > void pushBack(Stack*);
>
> In C, it's normal to hardcode simple structures like stacks.
and I'm not convinced this is a good idea. I've seen code where
application and (much more) container management code were intimately
intertwined. You can no longer see the beef for the tree (to
intertwine metephors).
I think this "In C, it's normal to hardcode simple structures like
stacks" slides you towards this.
> It's not
> clear to me whether this is a strong point or a weak point of the
> language, but it's generally easier to create a stack and stacktop
> index with whatever structure you're pushing and popping than to mess
> about with generic stack types. On feature is that your expression
> parser, or whatever it is you are using the stack for, does not have a
> dependency on a stack module.
>
> > typedef struct base
> > {
> > int type;
> > // shared data among all valid inputs
>
> > } Base;
>
> This is C++ implemented in C. Effectively what you are doing is
> writing your own set of conventions for handling polymorphic data
> types, and implementing them in C. Which means that C isn't the right
> language for this approach. Sometimes it's necessary to use the wrong
> language because of other considerations. However it should be a last
> resort, and done sparingly.-
[toc] | [prev] | [next] | [standalone]
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Date | 2012-01-23 23:42 +0000 |
| Message-ID | <slrnjhrs3c.1ls.grahn+nntp@frailea.sa.invalid> |
| In reply to | #16037 |
On Sun, 2012-01-22, Nick Keighley wrote: > On Jan 19, 12:23 pm, Malcolm McLean <malcolm.mcle...@btinternet.com> > wrote: >> On Jan 18, 9:53 pm, nroberts <roberts.n...@gmail.com> wrote: > >> > I keep getting told that what I write is more C++ like. I find it odd >> > because I'm actually using C keywords I rarely if ever use in C++ like >> > union. But two main examples come to mind: >> >> > First, I use opaque types to encapsulate data so I can depend on the >> > integrity of my structures. For example, when making a stack I had a >> > header like so: >> >> > struct stack; >> > typedef struct stack Stack; >> >> > Stack* createList(); >> > void* popFront(Stack*); >> > void pushBack(Stack*); >> >> In C, it's normal to hardcode simple structures like stacks. > > and I'm not convinced this is a good idea. I've seen code where > application and (much more) container management code were intimately > intertwined. You can no longer see the beef for the tree (to > intertwine metephors). > > I think this "In C, it's normal to hardcode simple structures like > stacks" slides you towards this. +1. I saw an example recently too. A queue of struct Foo, and batch processing of these struct Foo off the queue. These two things intertwined was /much/ harder to understand (and debug, and test, and document, and ...) than the two parts. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o .
[toc] | [prev] | [next] | [standalone]
| From | Rui Maciel <rui.maciel@gmail.com> |
|---|---|
| Date | 2012-01-19 14:51 +0000 |
| Message-ID | <jf9al4$gft$1@speranza.aioe.org> |
| In reply to | #15924 |
nroberts wrote: > I'm working on a C project and I come from C++ background. I used to > work with C 10 years ago though when I was first learning various > languages and used things like Xlib, Xt, etc... > > I keep getting told that what I write is more C++ like. I find it odd > because I'm actually using C keywords I rarely if ever use in C++ like > union. But two main examples come to mind: <snip/> From your description, it appears you tend to employ OO tricks in your code, mainly encapsulation and inheritance. That isn't necessarily the "C++ like" way of doing things, only the application of some principles associated with a particular programing paradigm. From this, I agree with you. It is a paradigm, not something unique to any particular programming language. Maybe some people see it as being something related to C++, as they associate OO with C++. Yet, C++ isn't the OO paradigm, and OO paradigm isn't the C++ programming language, nor Java or any other one. So, in the end the only question that I believe is relevant in this case is: does it matter? More specifically, are these OO tricks responsible for any problem? If they don't then why bother with them? Rui Maciel
[toc] | [prev] | [next] | [standalone]
| From | jgk@panix.com (Joe keane) |
|---|---|
| Date | 2012-01-19 23:04 +0000 |
| Message-ID | <jfa7hv$efi$1@reader1.panix.com> |
| In reply to | #15924 |
In article <31492b98-d71f-4a77-95f3-c150099f9b0d@y10g2000vbn.googlegroups.com>, nroberts <roberts.noah@gmail.com> wrote: >I've seen both of these used a lot in various C projects, but has it >gone out of style or something? It's just good programming. Good C code resembles C++ written in C. Bad C code resembles fettucine alfredo.
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2012-01-20 16:03 +1300 |
| Message-ID | <9ns3rfF524U5@mid.individual.net> |
| In reply to | #15924 |
On 01/19/12 10:53 AM, nroberts wrote:
> I'm working on a C project and I come from C++ background. I used to
> work with C 10 years ago though when I was first learning various
> languages and used things like Xlib, Xt, etc...
If you had used XView, you wouldn't be asking this question! XView was
my introduction to OO programming in C.
> I keep getting told that what I write is more C++ like. I find it odd
> because I'm actually using C keywords I rarely if ever use in C++ like
> union. But two main examples come to mind:
>
> First, I use opaque types to encapsulate data so I can depend on the
> integrity of my structures. For example, when making a stack I had a
> header like so:
>
> struct stack;
> typedef struct stack Stack;
>
> Stack* createList();
> void* popFront(Stack*);
> void pushBack(Stack*);
>
> etc...
>
> Another example is when I'm parsing an unknown string into one of
> several possibilities:
>
> typedef struct base
> {
> int type;
> // shared data among all valid inputs
> } Base;
>
> typedef struct variant_a
> {
> Base base;
> // particular data members
> } VariantA;
>
> .... more variants...
>
> typedef union blob
> {
> int type;
> Base base;
> VariantA a;
> ...etc...
> } Blob;
>
> Blob * parse(char const*);
>
> I've seen both of these used a lot in various C projects, but has it
> gone out of style or something? I suppose it's kind of OOesque, but
> I've always thought of that as one paradigm for use in any
> language...not something unique to any particular one. Is that an
> unpopular conception? If I were to do something similar in C++ it
> would look absolutely nothing like the above...why do people think
> it's C++ like? Are they full of it or am I? Both? Neither?
You are correct, what you are writing is OO C, not C++ like C. If it
passes its tests and your colleagues understand it, go for it.
--
Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | Malcolm McLean <malcolm.mclean5@btinternet.com> |
|---|---|
| Date | 2012-01-20 06:01 -0800 |
| Message-ID | <8a99d366-622b-4916-b34b-3f529bc408a5@i25g2000vbt.googlegroups.com> |
| In reply to | #15966 |
On Jan 20, 3:03 am, Ian Collins <ian-n...@hotmail.com> wrote: > > You are correct, what you are writing is OO C, not C++ like C. If it > passes its tests and your colleagues understand it, go for it. > OO C is C++-like C. C++ provides support for object-orientation, C doesn't. Of course ultimately a design paradigm is independent of the language used to implement it, and you can emulate any language wtih any other (hence the claim sometimes made that every sufficiently large project contains a bug-ridden and informally specified implementation of Lisp). But it's a lot easier to use languages for the purposes for which they are intended. -- Visit my website http://www.malcolmmclean.site11.com/www
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2012-01-21 08:03 +1300 |
| Message-ID | <9nts41F524U9@mid.individual.net> |
| In reply to | #15977 |
On 01/21/12 03:01 AM, Malcolm McLean wrote: > On Jan 20, 3:03 am, Ian Collins<ian-n...@hotmail.com> wrote: >> >> You are correct, what you are writing is OO C, not C++ like C. If it >> passes its tests and your colleagues understand it, go for it. >> > OO C is C++-like C. No, it's OO C. OO C was around before we had C++. > C++ provides support for object-orientation, C doesn't. Of course > ultimately a design paradigm is independent of the language used to > implement it, and you can emulate any language wtih any other (hence > the claim sometimes made that every sufficiently large project > contains a bug-ridden and informally specified implementation of > Lisp). But it's a lot easier to use languages for the purposes for > which they are intended. The key point is because of a lack of language support, OO C doesn't look like C++. The question could have been "Am I being too Java like?" -- Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | Malcolm McLean <malcolm.mclean5@btinternet.com> |
|---|---|
| Date | 2012-01-21 12:31 -0800 |
| Message-ID | <3d563fa0-899b-4450-87be-34558b2ba463@o13g2000vbf.googlegroups.com> |
| In reply to | #15982 |
On Jan 20, 7:03 pm, Ian Collins <ian-n...@hotmail.com> wrote: > > The key point is because of a lack of language support, OO C doesn't > look like C++. The question could have been "Am I being too Java like?" > Java's a more pure OO language than C++. But C++ is similar to C. C compilers usually ship with a C++ compiler, and C++ compilers always have either a C mode or a twin C compiler. So normally my advice to someone trying to write OO C would be to go to C++. Going to Java might be a better bet, but raises very many other issues, for instance the Java swing library looks different to the C/C++ GDI library on Windows. -- MiniBasic - how to write a script interpreter http://www.malcolmmclean.site11.com/www
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2012-01-22 10:18 +1300 |
| Message-ID | <9o0octF524U12@mid.individual.net> |
| In reply to | #16014 |
On 01/22/12 09:31 AM, Malcolm McLean wrote: > On Jan 20, 7:03 pm, Ian Collins<ian-n...@hotmail.com> wrote: >> >> The key point is because of a lack of language support, OO C doesn't >> look like C++. The question could have been "Am I being too Java like?" >> > Java's a more pure OO language than C++. But C++ is similar to C. C > compilers usually ship with a C++ compiler, and C++ compilers always > have either a C mode or a twin C compiler. So normally my advice to > someone trying to write OO C would be to go to C++. That is reasonable advice. But often circumstances prevent the introduction of C++ into a C project. But the point still remains that OO C isn't C++ like, it's how not to write OO in C++ like! -- Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | cri@tiac.net (Richard Harter) |
|---|---|
| Date | 2012-01-20 05:22 +0000 |
| Message-ID | <4f18f820.184550742@text.giganews.com> |
| In reply to | #15924 |
On Wed, 18 Jan 2012 13:53:57 -0800 (PST), nroberts <roberts.noah@gmail.com> wrote: >I'm working on a C project and I come from C++ background. I used to >work with C 10 years ago though when I was first learning various >languages and used things like Xlib, Xt, etc... > >I keep getting told that what I write is more C++ like. I find it odd >because I'm actually using C keywords I rarely if ever use in C++ like >union. But two main examples come to mind: > >First, I use opaque types to encapsulate data so I can depend on the >integrity of my structures. For example, when making a stack I had a >header like so: > >struct stack; >typedef struct stack Stack; > >Stack* createList(); >void* popFront(Stack*); >void pushBack(Stack*); > >etc... My take is that this is neither C++ like nor OO like, but instead is the older concept of an abstract data type. An ADT has atoms of type T and a suite of operations on the atoms. OO adds concepts such as inheritance. C++ adds, well, ....
[toc] | [prev] | [next] | [standalone]
| From | Marco <prenom_nomus@yahoo.com> |
|---|---|
| Date | 2012-01-21 07:29 -0800 |
| Message-ID | <22820634.607.1327159745654.JavaMail.geo-discussion-forums@yqhl41> |
| In reply to | #15924 |
no C allows many styles of programming yours is similar to: "C Interfaces and Implementations: Techniques for Creating Reusable Software" by Hanson <http://sites.google.com/site/cinterfacesimplementations/> <http://books.google.com/books/about/C_interfaces_and_implementations.html?id=76ZQAAAAMAAJ> keep using typedef ignore the naysayers
[toc] | [prev] | [next] | [standalone]
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Date | 2012-01-24 12:13 +0000 |
| Message-ID | <slrnjht82h.1ls.grahn+nntp@frailea.sa.invalid> |
| In reply to | #16009 |
On Sat, 2012-01-21, Marco wrote: ... > keep using typedef ignore the naysayers If you really care, you should really provide some arguments, like us "naysayers" did ... /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o .
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <txr@alumni.caltech.edu> |
|---|---|
| Date | 2012-01-31 14:32 -0800 |
| Message-ID | <kfny5sn1p0y.fsf@x-alumni2.alumni.caltech.edu> |
| In reply to | #16095 |
Jorgen Grahn <grahn+nntp@snipabacken.se> writes: > On Sat, 2012-01-21, Marco wrote: > ... >> keep using typedef ignore the naysayers > > If you really care, you should really provide some arguments, > like us "naysayers" did ... You mean arguments like "I don't like using typedefs"? I didn't see any comments in this thread that amounted to anything more than a statement of personal preference or opinion, from those opposing the use of typedefs. OTOH, there were several comments from people in favor of typedefs that gave reasons to prefer typedefs (in some cases) that are at least somewhat objective, rather than just stating a preference.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2012-01-31 15:32 -0800 |
| Message-ID | <lnzkd3wirb.fsf@nuthaus.mib.org> |
| In reply to | #16529 |
Tim Rentsch <txr@alumni.caltech.edu> writes:
> Jorgen Grahn <grahn+nntp@snipabacken.se> writes:
>
>> On Sat, 2012-01-21, Marco wrote:
>> ...
>>> keep using typedef ignore the naysayers
>>
>> If you really care, you should really provide some arguments,
>> like us "naysayers" did ...
>
> You mean arguments like "I don't like using typedefs"? I didn't
> see any comments in this thread that amounted to anything more
> than a statement of personal preference or opinion, from those
> opposing the use of typedefs. OTOH, there were several comments
> from people in favor of typedefs that gave reasons to prefer
> typedefs (in some cases) that are at least somewhat objective,
> rather than just stating a preference.
A typedef for a struct type creates a new name (such as "foo") for a
type that already has a perfectly valid name (such as "struct foo").
The "struct foo" name still has to be used inside the struct definition
if the type declares a pointer to the same type (unless you use a
forward declaration). Using distinct identifiers for the tag and the
typedef name are different identifers, which is very common, can lead to
confusion.
Using a typedef for a struct type has few benefits. The drawbacks are
not terribly serious if you do it right, but in my opinion the benefits
are minor enough that it's not worth doing.
Of course if you think that having a one-word name for a type is a
significant benefit, then you're going to disagree with this argument.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2012-01-31 19:46 -0800 |
| Message-ID | <lnipjrw6zu.fsf@nuthaus.mib.org> |
| In reply to | #16534 |
Keith Thompson <kst-u@mib.org> writes:
[...]
> A typedef for a struct type creates a new name (such as "foo") for a
> type that already has a perfectly valid name (such as "struct foo").
> The "struct foo" name still has to be used inside the struct definition
> if the type declares a pointer to the same type (unless you use a
> forward declaration). Using distinct identifiers for the tag and the
> typedef name are different identifers, which is very common, can lead to
> confusion.
[...]
Poor editing on that last sentence; I meant:
Using distinct identifiers for the tag and the typedef name, which is
very common, can lead to confusion.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | Shao Miller <sha0.miller@gmail.com> |
|---|---|
| Date | 2012-01-31 23:54 -0500 |
| Message-ID | <jgagh7$ebi$1@dont-email.me> |
| In reply to | #16534 |
On 1/31/2012 18:32, Keith Thompson wrote: > > A typedef for a struct type creates a new name (such as "foo") for a > type that already has a perfectly valid name (such as "struct foo"). > The "struct foo" name still has to be used inside the struct definition > if the type declares a pointer to the same type (unless you use a > forward declaration). Using distinct identifiers for the tag and the > typedef name are different identifers, which is very common, can lead to > confusion. > > Using a typedef for a struct type has few benefits. The drawbacks are > not terribly serious if you do it right, but in my opinion the benefits > are minor enough that it's not worth doing. > > Of course if you think that having a one-word name for a type is a > significant benefit, then you're going to disagree with this argument. > If I have 'struct cat' and want an instance, or even a pointer to such, I might like to name the instance (or pointer) 'cat'. struct cat * cat; But that's no good, so maybe I'd do: struct s_cat * cat; That seems better, but if I have the 's_' there to indicate a 'struct' type, I might as well 'typedef' it: typedef struct s_cat s_cat; /* or maybe */ typedef struct s_cat S_CAT; S_CAT * cat; ...Or such. -- "The stationery store has moved. Aaargh!"
[toc] | [prev] | [next] | [standalone]
Page 3 of 5 — ← Prev page 1 2 [3] 4 5 Next page →
Back to top | Article view | comp.lang.c
csiph-web