Thread: Questions about styling in C/C++....

  1. #1
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665

    Questions about styling in C/C++....

    Hello All,

    So I got into contact with the author of an open-source meshing project and his results look fantastic. However, looking at the code... I'm a bit mortified.

    For one, you know what settles the debate between using CamelCase and underscores? Using neither! (The real answer is, for the love of God use either one, please!)

    Instead of such awesome things as push_back, I see pushback everywhere! And not only that, the style isn't even consistent in the project. Some functions are_written_like_this but not all. NotOneSingleUseOfCamelCase, ever. itiseitherthisornothingatall.

    There is also some code that uses a 90's implementation of robust arithmetic(Fast Robust Predicates for Computational Geometry) but I googled around and heard that macros are evil. And I can see. The code is incredibly hard to follow. I'm reading the paper and the paper seems fine but macros seem God awful. Like, I'm so confused about his use of bvirt. Like, how can you just declare that in a macro? Is it because bvirt is defined in each function that uses it?

    I'm just really confused about the robust code and I have to ask, is this an example of good coding style? It seems pretty terrible to me.

    So I guess my question is, if I'm serious about contributing, do I just throw in my own style? Or should I just examine his methodologies and re-implement my own version that's readable?

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    *linked code*
    O_o

    Is the scheme uncommon? Yes.
    Is the scheme ugly? Yes.
    Should you "throw in" a different style? No.

    I found the scheme to be consistent enough to gain understanding and insight into any particular bit of the code thanks to the expectations set in several quality comments. The code isn't perfect. The implementation makes some poor interface choices. A few of the comments are pointless. However, the scheme is largely consistent, and many of the comments answer important questions about the code. In fact, the comments answer some of your questions.

    Is the code your complaining about of similar quality as the, indirectly, linked code? If so, I'd advise you to spend more time getting familiar with the code before considering either option you've considered. Very likely, you have found yourself in an unfamiliar forest only to dismiss the trees.

    [Edit]
    To be clear, I'm using "quality" to refer to the consistency and informative nature of the comments.
    [/Edit]

    Soma
    Last edited by phantomotap; 05-16-2014 at 12:33 PM.
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  3. #3
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Interesting. Fair enough.

    Then would you be able to help me figure out this binary addition? I get the ideas of non-overlapping but I have no idea how this addition is being done. It's figure 3 in the long paper on the website posted above.

    Basically, we write :

    a = 1 1 1 1 0 0
    b = 0 0 1 0 0 1

    with a + b = x = 1 0 0 1 0 0 0

    I get that this is supposed to be inaccurate and the figure later shows the actual full expansion as a + b = x + y where x and y are non-overlapping expansions.

    My biggest question is, how on Earth do they get x that way? It's driving me nuts.

  4. #4
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Okay, I answer my own question and I feel like an idiot now.

    It's because he treats it like an actual float and not a binary literal (I'm slow sometimes) so we really have 1 1 1 1 x 2^2 + 1 0 0 1 x 2^0 so when you add those, you get 1 0 0 0 1 0 1 but because this is supposed to be a float, the computer rounds it to the nearest so it becomes 1 0 0 1 x 2^3.

    *sigh*

    So much nerd rage. But I finally figured it out and I'm incredibly happy now

  5. #5
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    As I've said before, I do not mathematics all that well. (I had to read the relevant section a few times.) You should keep that in mind.

    My understanding is that we are dealing exclusively with "n-bit" values and an implied power.

    (So, we are dealing with "floating point" numbers as implemented "in the wild".)

    According to my understanding, the "answer" isn't `b1000101'. The "answer" can't be `b1000101' because we don't have enough bits to store that value.

    We have four bits; we can store only four bits. We may store either `b1000' or `b1001'. We store `b1001' because that value is "nearer" the exact value.

    The rest is just powers.

    [Edit]
    I'm going to leave the below comment because of the near timing, but I still wanted to say that I'm pleased that I was at least wrong about you not taking time to understand the context.
    [/Edit]

    By the by, you should not expect me to do this a second time with such a small offering of effort. I responded exclusively because the article had my attention. If you want to do the job, you are responsible for whatever research is necessary to understand the material. Yes, asking for help is part of that research, but I don't believe you put in enough effort to parse the context of the example.

    *shrug*

    Of course, I may be wrong about the example. In such a case, you'll still need study the context.

    Soma
    Last edited by phantomotap; 05-16-2014 at 02:23 PM.
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  6. #6
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    It' not like I don't know binary addition. It's just that the figure neglects to mention that rounding is taking place because of storage constraints (which should've been obvious). I think the author was assuming a much more intelligent audience than the one currently doing the reading (me lol).

    Still, once I finally figured it out I realize that his solution is very elegant and is, well, rather robust. Which is good. It means I'm closer to understanding how to perform exact arithmetic which is a basic requirement in the world of computational geometry. I'm beginning to actually enjoy studying the paper now.

  7. #7
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I'm beginning to actually enjoy studying the paper now.
    O_o

    If you ask me, you should have enjoyed "the hunt" in the first place.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. trouble styling xml with xsl
    By c_weed in forum Tech Board
    Replies: 0
    Last Post: 06-11-2011, 11:56 PM
  2. IDE questions
    By SterlingM in forum C++ Programming
    Replies: 1
    Last Post: 10-19-2009, 05:13 AM
  3. questions
    By sKeL` in forum C Programming
    Replies: 8
    Last Post: 09-24-2009, 11:04 PM
  4. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  5. some questions
    By hiya in forum Windows Programming
    Replies: 6
    Last Post: 06-17-2005, 04:28 PM