Rewrite!

This is a discussion on Rewrite! within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Critiques please. This is a very preliminary version . The code hasn't been fully debugged and the tutorial isn't presented ...

  1. #1
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796

    Rewrite!

    Critiques please. This is a very preliminary version. The code hasn't been fully debugged and the tutorial isn't presented with all of the frills that I like to add. But I'd like to know how this one compares to the other one before I finish the new one and replace the old one.

    Arigato!
    My best code is written with the delete key.

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    My comments after reading it through once:

    1) In your diagram showing leaf nodes, you left out some leaf nodes, which some people may find confusing.

    2) In the first code example under the Search heading, you have root declared as "struct jsw_node root", but then compare it to NULL. Bwuh?

    3) Same code example. You seem to be using pointer notation for referencing members of the structs, but they're not pointers. (Edit: you seem to be doing this in most examples).

    4) In your insertion example code, you call the make_node() function, but don't define it. (Yes, it's trivial, but I'm feeling nitpicky).

    At this point, the pointer arithmetic on non-pointers has started to hurt my brain, so I'm going to take a nap. I'm pretty sure I've just missed something, but I can't seem to figure out what.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    1) Hehe, gomen. I'll fix that straight away. (done)

    2) You've discovered a bug in my auto-formatting program. They really are supposed to be pointers. (fixed)

    4) I'm pretty sure I describe how it works before that, but I'll double check. (added a quick comment to that effect)
    Last edited by Prelude; 11-01-2005 at 03:08 PM.
    My best code is written with the delete key.

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Regarding #4, you describe it later on in the article actually. Might want to move the description. (Specificly under the "Parent Pointers" section)
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Alrighty. I've read through it some more:

    1) "int dir = root->data < data;"

    I don't have any copies of the C standards, but is the "<" operator guaranteed to return 0 and 1? Or is it 0 and non-zero? Same thing with the "==" operator.

    2) Your use of the comma operator may throw off some users. It's very rarely used, so not everyone will know what it does.

    So far I've read up to Traversal. I'll read from there on tomorrow.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  6. #6
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    I agree, avoid the comma operator. Especially because, IIRC, it's designed to be used where you can't seperate the statements (like between the " ; ; " in the top of a 'for' loop).

    1) The 'heir' word. Theres two issues with this: A) It can confuse people who aren't good with english, or have trouble pronouncing words like this as they read it (me), and B) The word "child" is used in nearly every other example on trees - it's a bit of a convention.

    2) While I agree the link[0/1] thing is faster and better than node->Left and node->Right, understanding it distracts from understanding the actual tree. You even devote a couple of paragraphs explaining why, and also why your comparrison operators are in reverse. Perhaps, for the sake of clarity in the tutorial, you could use 'Left' and 'Right' and add the link[0/1] thing at the end?

    I guess what I'm getting at is the primary focus of the tutorial is meant to introduce BST's, so if you're a struggling college student with a test tommorow and you need to boslter your understanding, these extra conventions/practices (no matter how important they are) just add to the clutter.

    Also, a style thing: I don't like the special starting capital letter of every paragraph. It's great for the start of a section, but I find it a little annoying paragraph after paragraph. Although, it's fun to try and make an "acrostic poem" out of the paragraphs. That's a personal thing though, YMMV.

    I understand this can be frustrating though - there's an awful lot of knowledge in your head, you want to get it into everyone else's head, but if you try and teach too much it just makes it harder.

    Prelude, have you ever considered becoming a published author? I'd certainly rather read a book on C/C++/Java by you than the boring, dry, fluffy text books out there.

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >is the "<" operator guaranteed to return 0 and 1?
    Yes. That's actually an issue we've touched on here before, but in a different context (of someone trying to correct one of my answers ).

    >Your use of the comma operator may throw off some users.
    That's a good point. I think that in this case it's a safe and understandable usage, but it might be a good idea to either remove it or explain why it's used initially.

    >The word "child" is used in nearly every other example on trees -
    >it's a bit of a convention.
    So is the right-left pointer idiom, and I'm not sure that's a good convention. In concept, yes, but in practice I think the array is better. I probably should change heir to something more obvious, like succ.

    >Perhaps, for the sake of clarity in the tutorial, you could
    >use 'Left' and 'Right' and add the link[0/1] thing at the end?
    I debated that with myself and ended up deciding that it would be better to avoid the common convention entirely in favor of what I consider to be better practice. It really is easier once you get used to it because all of those symmetric cases are removed. I think it's those symmetric cases that make trees daunting. First you have the trouble of making sure you don't make mistakes, which is very easy if the only difference between the left and right cases is the name of the link. Second, it can make the code much longer, which stops some people cold. By removing redundant code and making the functions shorter, I make them more accessible to beginners and people who don't want to wade through pages of source to understand what's going on. A couple of paragraphs to help them understand the idiom is worth the benefit from the idiom, no?

    >have you ever considered becoming a published author?
    Yes, in fact I have a book in the works and a publisher is interested in it. But it's a fantasy series, not a programming text. I'm not sure I could collect all of my thoughts together in such a way as to make a good programming book.
    My best code is written with the delete key.

  8. #8
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    I would certainly buy a programming book written by Prelude!

    One quick question about you 'Deletion' section under Binary Search trees. Shouldn't the 5 be a 7?
    Attached Images Attached Images  
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Shouldn't the 5 be a 7?
    Yep.
    My best code is written with the delete key.

  10. #10
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    I would rather read a Prelude book on Prelude..
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. rewrite C function in C#
    By khdani in forum C# Programming
    Replies: 5
    Last Post: 04-05-2009, 08:44 PM
  2. rewrite to file
    By mystic-d in forum C Programming
    Replies: 1
    Last Post: 12-07-2006, 05:36 AM
  3. rewrite to file
    By mystic-d in forum C++ Programming
    Replies: 1
    Last Post: 12-07-2006, 05:33 AM
  4. Rewrite using functions.
    By g.mail in forum C++ Programming
    Replies: 7
    Last Post: 11-15-2006, 07:06 PM
  5. Contest Sign-Up Thread: Rewrite Mid() from VB
    By Eibro in forum Contests Board
    Replies: 61
    Last Post: 03-25-2003, 08:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21