Re: function for difference two dates

Discussion in 'C Programming' started by Ian Collins, Jun 16, 2010.

  1. Ian Collins

    Ian Collins Guest

    On 06/16/10 09:28 PM, io_x wrote:
    > [comp.lang.c,comp.lang.c++]
    >
    > what about one function that do difference of 2 dates?
    > where date is class or struct of type
    > int sec, min, ora, day, mese, anno;
    > where the difference is in
    > sec, min, ora, day, mese, anno
    >
    > #define R return


    Why?

    --
    Ian Collins
     
    Ian Collins, Jun 16, 2010
    #1
    1. Advertising

  2. Ian Collins <> writes:
    > On 06/16/10 09:28 PM, io_x wrote:
    >> [comp.lang.c,comp.lang.c++]
    >>
    >> what about one function that do difference of 2 dates?
    >> where date is class or struct of type
    >> int sec, min, ora, day, mese, anno;
    >> where the difference is in
    >> sec, min, ora, day, mese, anno
    >>
    >> #define R return

    >
    > Why?


    He's been asked this before and he's answered before. If he answers
    this time, I don't expect his answer to make any more sense than the
    last one. (He apparently thinks R is actually better than "return";
    I don't remember his rationale.)

    Or, for io_x's benefit:

    H's b a t b a h's a b. I h a t t, I d't e h a t m a m s t t l o.
    (H a t R i a b t "r"; I d't r h r.)

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jun 16, 2010
    #2
    1. Advertising

  3. Ian Collins

    Ike Naar Guest

    In article <>,
    Keith Thompson <> wrote:
    >Ian Collins <> writes:
    >> On 06/16/10 09:28 PM, io_x wrote:
    >>> #define R return

    >>
    >> Why?

    >
    >He's been asked this before and he's answered before. If he answers
    >this time, I don't expect his answer to make any more sense than the
    >last one. (He apparently thinks R is actually better than "return";
    >I don't remember his rationale.)
    >
    >Or, for io_x's benefit:
    >
    >H's b a t b a h's a b. I h a t t, I d't e h a t m a m s t t l o.
    >(H a t R i a b t "r"; I d't r h r.)


    At least io_x shows us the definitions for his silly macros.
    For our benefit, could you show yours?
    --

    SDF Public Access UNIX System - http://sdf.lonestar.org
     
    Ike Naar, Jun 17, 2010
    #3
  4. Ian Collins

    Öö Tiib Guest

    On Jun 17, 12:22 pm, "io_x" <> wrote:
    > "Ian Collins" <> ha scritto nel messaggionews:...
    >
    > > On 06/16/10 09:28 PM, io_x wrote:

    >
    > >> #define  R  return

    >
    > > Why?

    >
    > why not?


    Because you will hate it when you have to deal with code of other
    macro-magician with different ideas. R is only start. It goes on:

    #define G  goto
    #define W while
    #define S switch
    #define C case

    Then come patterns:

    #define EI else if
    #define FI(END) for(int i=0; i<END; i++)

    So it goes. I have seen it at its final stage. Code was readable only
    for its author in raw form. Normal programmers had to let compiler to
    preprocess it first to read it. Also author had difficulties to read
    normal code.

    > "R" it is small, many spaces saved, [more code for line an better indented]
    > than for read is better than return
    > at last here
    >
    > than "#define  R return" is not standard C or C++?
    >
    > you whoudl say not understand standard C or C++? :)


    There are endless things that must compile by standard. No undefined
    behavior involved:

    char* hehs = "Endless fun and lulz";
    unsigned dozen = 6,014; // 12
    if ( -1 > dozen ) // true
    {
    delete this;
    throw dozen[hehs]; // 'a'
    }

    Even as joke it is not too funny.
     
    Öö Tiib, Jun 17, 2010
    #4
  5. (Ike Naar) writes:
    > In article <>,
    > Keith Thompson <> wrote:
    >>Ian Collins <> writes:
    >>> On 06/16/10 09:28 PM, io_x wrote:
    >>>> #define R return
    >>>
    >>> Why?

    >>
    >>He's been asked this before and he's answered before. If he answers
    >>this time, I don't expect his answer to make any more sense than the
    >>last one. (He apparently thinks R is actually better than "return";
    >>I don't remember his rationale.)
    >>
    >>Or, for io_x's benefit:
    >>
    >>H's b a t b a h's a b. I h a t t, I d't e h a t m a m s t t l o.
    >>(H a t R i a b t "r"; I d't r h r.)

    >
    > At least io_x shows us the definitions for his silly macros.
    > For our benefit, could you show yours?


    It's just the previous paragraph with each word abbreviated to its
    initial letter.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jun 17, 2010
    #5
  6. "io_x" <> writes:
    > "Ian Collins" <> ha scritto nel messaggio
    > news:...
    >> On 06/16/10 09:28 PM, io_x wrote:
    >>> [comp.lang.c,comp.lang.c++]
    >>>
    >>> what about one function that do difference of 2 dates?
    >>> where date is class or struct of type
    >>> int sec, min, ora, day, mese, anno;
    >>> where the difference is in
    >>> sec, min, ora, day, mese, anno
    >>>
    >>> #define R return

    >>
    >> Why?

    >
    > why not?
    > "R" it is small, many spaces saved, [more code for line an better indented]
    > than for read is better than return
    > at last here
    >
    > than "#define R return" is not standard C or C++?
    >
    > you whoudl say not understand standard C or C++? :)


    If I see

    return 42;

    I know what "return" means. If I see

    R 42;

    I have to figure out, not just what R means, but what *you* mean
    by R. Sure, the #define is there, but I have to spend extra time
    finding it to make sure you didn't define it as "restrict" or
    "register", or "(void)".

    It makes the code more difficult to read. It saves you a tiny amount
    of time and costs anyone trying to read your code a great deal more
    with no corresponding benefit.

    Code is meant to be read by humans, especially code posted
    to Usenet. Consider that, over the years, multiple people have
    strongly criticized your coding style, have told you that it makes
    your code more difficult to read, and in many cases have killfiled
    you because of it. I have *never* seen anyone other than you say
    anything positive or even neutral about it.

    You demonstrate your disregard for the convenience of the people
    you're asking to read your code.

    For myself, I've solved the problem by not wasting my time reading it.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jun 17, 2010
    #6
  7. Ian Collins

    Seebs Guest

    On 2010-06-17, Keith Thompson <> wrote:
    > It makes the code more difficult to read. It saves you a tiny amount
    > of time and costs anyone trying to read your code a great deal more
    > with no corresponding benefit.


    I disagree.

    I do not think it saves any time at all.

    > Code is meant to be read by humans, especially code posted
    > to Usenet. Consider that, over the years, multiple people have
    > strongly criticized your coding style, have told you that it makes
    > your code more difficult to read, and in many cases have killfiled
    > you because of it. I have *never* seen anyone other than you say
    > anything positive or even neutral about it.


    I killfiled him about the second time I saw it. About the nicest thing
    I could say about his posts is that some of them are at least lucid,
    even though they're wrong.

    I've sort of assumed he's just trolling. He's got a bit too much technical
    ability to be as stupid as he acts.

    -s
    --
    Copyright 2010, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
     
    Seebs, Jun 17, 2010
    #7
  8. Ian Collins

    Dann Corbit Guest

    In article <>, says...
    >
    > "io_x" <> writes:
    > > "Ian Collins" <> ha scritto nel messaggio
    > > news:...
    > >> On 06/16/10 09:28 PM, io_x wrote:
    > >>> [comp.lang.c,comp.lang.c++]
    > >>>
    > >>> what about one function that do difference of 2 dates?
    > >>> where date is class or struct of type
    > >>> int sec, min, ora, day, mese, anno;
    > >>> where the difference is in
    > >>> sec, min, ora, day, mese, anno
    > >>>
    > >>> #define R return
    > >>
    > >> Why?

    > >
    > > why not?
    > > "R" it is small, many spaces saved, [more code for line an better indented]
    > > than for read is better than return
    > > at last here
    > >
    > > than "#define R return" is not standard C or C++?
    > >
    > > you whoudl say not understand standard C or C++? :)

    >
    > If I see
    >
    > return 42;
    >
    > I know what "return" means. If I see
    >
    > R 42;
    >
    > I have to figure out, not just what R means, but what *you* mean
    > by R. Sure, the #define is there, but I have to spend extra time
    > finding it to make sure you didn't define it as "restrict" or
    > "register", or "(void)".
    >
    > It makes the code more difficult to read. It saves you a tiny amount
    > of time and costs anyone trying to read your code a great deal more
    > with no corresponding benefit.
    >
    > Code is meant to be read by humans, especially code posted
    > to Usenet. Consider that, over the years, multiple people have
    > strongly criticized your coding style, have told you that it makes
    > your code more difficult to read, and in many cases have killfiled
    > you because of it. I have *never* seen anyone other than you say
    > anything positive or even neutral about it.
    >


    First of all, as everyone knows, macros that are not simply numbers
    (functional or action type) are evil. Careful construction and use can
    render them useful in rare circumstance, but in general they are a bad
    idea for something besides numerical constants or token pasting formats,
    (and other things of that nature).

    Second of all, will the maintenance programmer now realize that 13 of
    the 26 letters of the alphabet have been used up and if he defines a
    variable with that name it will cause the program to act in an
    unexpected manner?

    C tends to be terse enough. There are lots of things that are legal in
    the C language, but that does not mean that we ought to do them.
    (E.g. we can make an entire 64K function be nothing more than a gigantic
    return statement and it will work. That does not make it a good idea).
     
    Dann Corbit, Jun 17, 2010
    #8
  9. Ian Collins

    bart.c Guest

    "Ike Naar" <> wrote in message
    news:hvcj8h$l7$-eu.org...
    > In article <>,
    > Keith Thompson <> wrote:
    >>Ian Collins <> writes:
    >>> On 06/16/10 09:28 PM, io_x wrote:
    >>>> #define R return
    >>>
    >>> Why?

    >>
    >>He's been asked this before and he's answered before. If he answers
    >>this time, I don't expect his answer to make any more sense than the
    >>last one. (He apparently thinks R is actually better than "return";
    >>I don't remember his rationale.)
    >>
    >>Or, for io_x's benefit:
    >>
    >>H's b a t b a h's a b. I h a t t, I d't e h a t m a m s t t l o.
    >>(H a t R i a b t "r"; I d't r h r.)

    >
    > At least io_x shows us the definitions for his silly macros.
    > For our benefit, could you show yours?


    It would be something like the following, however it doesn't really work
    because the same letter is shared by many words, so I've added an index
    here:

    #define H he
    #define S s
    #define B been
    #define A asked
    #define T this
    #define B2 before
    #define A2 and
    #define A3 answered
    #define I if
    #define A4 answers
    #define T2 time
    #define I2 i
    #define D don
    #define T3 t
    #define E expect
    #define H2 his
    #define A5 answer
    #define T4 to
    #define M make
    #define A6 any
    #define M2 more
    #define S2 sense
    #define T5 than
    #define T6 the
    #define L last
    #define O one
    #define A7 apparently
    #define T7 thinks
    #define R r
    #define I3 is
    #define A8 actually
    #define B3 better
    #define R2 return
    #define R3 remember
    #define R4 rationale

    --
    Bartc
     
    bart.c, Jun 17, 2010
    #9
  10. Ian Collins

    Ike Naar Guest

    In article <>,
    Keith Thompson <> wrote:
    >It's just the previous paragraph with each word abbreviated to its
    >initial letter.


    [slaps forehead] Thanks.
    --

    SDF Public Access UNIX System - http://sdf.lonestar.org
     
    Ike Naar, Jun 17, 2010
    #10
  11. Ian Collins

    bart.c Guest

    "io_x" <> wrote in message
    news:4c1bc6dd$0$18995$...
    >
    > "Keith Thompson" <> ha scritto nel messaggio
    > news:...


    >> I have to figure out, not just what R means, but what *you* mean
    >> by R. Sure, the #define is there, but I have to spend extra time
    >> finding it to make sure you didn't define it as "restrict" or
    >> "register", or "(void)".

    >
    > you spend the extra time
    > mult that for 4 or 5 (the number of the macros)
    > it can be how much? 5 minuts
    >
    > and for the rest of the code all will be ok, no search more


    My text editor is an ancient text-mode one I wrote a couple of decades ago I
    think.

    Yet I still managed to define the first few function keys as "return ", "for
    (", "printf("" and so on. It took half a minute.

    Now it is even easier to type these keywords, as you don't need to use the
    shift key or follow with a space. (And you can also add " (" for for/while,
    and "("" for printf, which would look terrible if you tried it with macros:
    W i>0) ...;)

    The advantage is that the result is readable by everybody, who additionally
    don't have to suffer from your inability to type, or to use better tools.
    (As it happens, I don't have a problem with typing out keywords in full;
    it's punctuation I don't like..)

    --
    Bartc
     
    bart.c, Jun 18, 2010
    #11
  12. Ian Collins

    Ian Collins Guest

    On 06/17/10 09:22 PM, io_x wrote:
    > "Ian Collins"<> ha scritto nel messaggio
    > news:...
    >> On 06/16/10 09:28 PM, io_x wrote:
    >>> [comp.lang.c,comp.lang.c++]
    >>>
    >>> what about one function that do difference of 2 dates?
    >>> where date is class or struct of type
    >>> int sec, min, ora, day, mese, anno;
    >>> where the difference is in
    >>> sec, min, ora, day, mese, anno
    >>>
    >>> #define R return

    >>
    >> Why?

    >
    > why not?
    > "R" it is small, many spaces saved, [more code for line an better indented]
    > than for read is better than return
    > at last here
    >
    > than "#define R return" is not standard C or C++?
    >
    > you whoudl say not understand standard C or C++? :)


    If you ever try and use that style on an opensource project or as part
    of professional team, you will quickly be told to stop.

    --
    Ian Collins
     
    Ian Collins, Jun 18, 2010
    #12
  13. Ian Collins

    Eric Sosman Guest

    On 6/18/2010 5:36 PM, Richard Heathfield wrote:
    > [... `#define R return' and similar foolishness ...]
    >
    > Clearly he is not interested in other people's opinion of his coding
    > style.[...]


    What makes you think this is his coding style? Anyone who
    actually used it for more than half an hour would discover its
    disadvantages for himself, without help from others. It's not
    his coding style at all: it's just his way of being annoying and
    proving himself a half-assed half-wit.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Jun 19, 2010
    #13
  14. Ian Collins

    Richard Bos Guest

    "io_x" <> wrote:

    > "Dann Corbit" <> ha scritto nel messaggio


    > > C tends to be terse enough.

    >
    > it is not true, nothing is enought terse


    You're an idiot.

    Not terse enough? How about this, then:

    **** off.

    Richard
     
    Richard Bos, Jun 19, 2010
    #14
  15. Eric Sosman <> writes:
    > On 6/18/2010 5:36 PM, Richard Heathfield wrote:
    >> [... `#define R return' and similar foolishness ...]
    >>
    >> Clearly he is not interested in other people's opinion of his coding
    >> style.[...]

    >
    > What makes you think this is his coding style? Anyone who
    > actually used it for more than half an hour would discover its
    > disadvantages for himself, without help from others. It's not
    > his coding style at all: it's just his way of being annoying and
    > proving himself a half-assed half-wit.


    If he only used it in code that nobody else ever looked at, it
    would be viable. After a little time, he'd get used to the idea
    that P means printf, R means return, and so forth. I see no reason
    to doubt that he uses it in his own code.

    He just doesn't seem to understand, after repeated and clear
    explanations, that it hurts his code's readability for other people.
    I don't know how he can fail to understand that, but somehow he
    manages.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jun 19, 2010
    #15
  16. On 18 June, 20:29, "io_x" <> wrote:
    > "Dann Corbit" <> ha scritto nel messaggionews:-september.org...


    <snip>

    > > C tends to be terse enough.

    >
    > it is not true, nothing is enought terse


    have you looked at APL?
     
    Nick Keighley, Jun 21, 2010
    #16
  17. On 21 June, 11:28, "io_x" <> wrote:
    > "Nick Keighley" <> ha scritto nel messaggionews:...
    > > On 18 June, 20:29, "io_x" <> wrote:
    > >> "Dann Corbit" <> ha scritto nel
    > >> messaggionews:-september.org...


    > >> > C tends to be terse enough.

    >
    > >> it is not true, nothing is enought terse

    >
    > > have you looked at APL?

    >
    > i did not look to APL, but know the problem
    > symbols can not be so many that someone can not remember well
    > what they mean


    APL achieves great terseness


    > but this is not again the point:
    > more terse i can write one algo in one language
    > more comment, more space for indentation i can use in meaningful way
    > in that language


    maybe if you weren't so terse you wouldn't so much comment. The aim is
    clarity. I could write a large comment and encode the machine code
    into some base 64 encoding. It'd be terse.


    > if for example C miss the power of goto,


    what? In what way does C "miss the power of goto"? Not that I agree
    goto *is* powerful.

    > could be some other
    > language that can use that for reduce the algo size to 1/2 or 1/8
    > [than the C one] and so increase the readability
    > of the expanded one [the one with the spaces and comments]


    well you're flying in the face of 40 years of good software
    engineering practice. But good luck.

    Try "Structure and Interpretation of Computer Programs"


    --

    I mean, if 10 years from now, when you are doing something quick and
    dirty,
    you suddenly visualize that I am looking over your shoulders and say
    to
    yourself, "Dijkstra would not have liked this", well that would be
    enough
    immortality for me.
    -- Edsger W Dijkstra
     
    Nick Keighley, Jun 21, 2010
    #17
  18. Ian Collins

    Dann Corbit Guest

    In article <e42d7387-6c6c-47be-986c-e4f8998ce030
    @z8g2000yqz.googlegroups.com>, says...
    >
    > On 21 June, 11:28, "io_x" <> wrote:
    > > "Nick Keighley" <> ha scritto nel messaggionews:...
    > > > On 18 June, 20:29, "io_x" <> wrote:
    > > >> "Dann Corbit" <> ha scritto nel
    > > >> messaggionews:-september.org...

    >
    > > >> > C tends to be terse enough.

    > >
    > > >> it is not true, nothing is enought terse

    > >
    > > > have you looked at APL?

    > >
    > > i did not look to APL, but know the problem
    > > symbols can not be so many that someone can not remember well
    > > what they mean

    >
    > APL achieves great terseness
    >
    >
    > > but this is not again the point:
    > > more terse i can write one algo in one language
    > > more comment, more space for indentation i can use in meaningful way
    > > in that language

    >
    > maybe if you weren't so terse you wouldn't so much comment. The aim is
    > clarity. I could write a large comment and encode the machine code
    > into some base 64 encoding. It'd be terse.
    >
    >
    > > if for example C miss the power of goto,

    >
    > what? In what way does C "miss the power of goto"? Not that I agree
    > goto *is* powerful.
    >
    > > could be some other
    > > language that can use that for reduce the algo size to 1/2 or 1/8
    > > [than the C one] and so increase the readability
    > > of the expanded one [the one with the spaces and comments]

    >
    > well you're flying in the face of 40 years of good software
    > engineering practice. But good luck.
    >
    > Try "Structure and Interpretation of Computer Programs"


    If terseness is the goal, then I suggest forth.
    In the end, the program will be a single word.
     
    Dann Corbit, Jun 21, 2010
    #18
  19. Ian Collins

    John Bode Guest

    On Jun 17, 4:22 am, "io_x" <> wrote:
    > "Ian Collins" <> ha scritto nel messaggionews:...
    >
    > > On 06/16/10 09:28 PM, io_x wrote:
    > >> [comp.lang.c,comp.lang.c++]

    >
    > >> what about one function that do difference of 2 dates?
    > >> where date is class or struct of type
    > >> int  sec, min, ora, day, mese, anno;
    > >> where the difference is in
    > >> sec, min, ora, day, mese, anno

    >
    > >> #define  R  return

    >
    > > Why?

    >
    > why not?


    Because it is *BAD PRACTICE*. It has been my experience over the last
    twenty years that replacing keywords with "shortcut" macros *always*
    creates maintenance headaches. Professional C programmers expect to
    see the regular complement of keywords in the code they are writing or
    maintaining. It allows them to understand the code more quickly and
    to modify it with some confidence that we know what they're doing.

    When someone starts replacing common keywords and structures (for(),
    while(), do-while(), etc.) with their own custom "shortcuts", it makes
    to code harder for other people to understand and modify. We have to
    go hunting for the macro definition, and once we find it, have to do
    our own mental preprocessing step every time we see it.

    It slows other people down, it makes it easier for mistakes to be
    missed (or created), and it doesn't actually buy you anything in the
    end. All you've saved is a few dozen characters in the source text,
    which is *meaningless*, and in exchange you've made that same code
    harder to read and maintain.

    If you're going to write C code, WRITE C CODE, not some bastard
    customized version that only you understand, *especially* if you
    expect other people to help you. Preprocessor abuse is probably
    responsible for more lost productivity than just about anything else.
     
    John Bode, Jun 21, 2010
    #19
  20. Ian Collins

    John Bode Guest

    On Jun 21, 4:47 pm, Richard Heathfield <> wrote:
    > John Bode wrote:
    >
    > <snip>
    >
    > > Preprocessor abuse is probably
    > > responsible for more lost productivity than just about anything else.

    >
    > WWII?
    >


    Yes.
     
    John Bode, Jun 21, 2010
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    869
    Rob Schieber
    Sep 30, 2005
  2. gops
    Replies:
    1
    Views:
    672
    Richard Heathfield
    Feb 10, 2004
  3. thebjorn
    Replies:
    23
    Views:
    1,556
    thebjorn
    Jul 29, 2006
  4. Ian Collins
    Replies:
    18
    Views:
    507
    Herbert Rosenau
    Jun 22, 2010
  5. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    199
    Mark Schupp
    Aug 9, 2004
Loading...

Share This Page