Death by 1000 Programming Sins

Pages: 1... 4567
For some reason that one doesn't get me, although I occasionally forget the private on Java member thinking that it's the default...
Why don't other languages have package private members? Screw friends!
ty, helios, for doing that sanity check for me - I am using ext3 on that drive, but it's a 1.5TB USB drive - perhaps the built-in buffering of the drive is impacting my results...
wow....what a read just so I can add:

153. not checking return values
154. not catching exceptions you throw or assuming something catches it
155. not attempting any code coverage tests

I think you can add all the 'Effective C++' and 'More Effective C++' stuff by Scott Meyers.

Number 153 is amusing when applied to 'new' some would just say "add more memory". And same for performance => "upgrade the server".

As for large classes, this is a tradeoff when considering simplicity. I created a reasonably large class when fixing someone's library in return I was able to see more of what the lib was doing, I streamlined the locking, removed 8 or so classes (thus removing 16 files - 8 headers and 8 impl files), the code was safer, easier, less buggy and it made me happier.

Last edited on

156. add copyright to your files
157. Leaving an ASCII Panda in your comments to annoy the next intern who will have the misfortune of working with your code.
                            ,d888888888b,
                           d8888888888888b                        _,ad8ba,_
                          d888888888888888)                     ,d888888888b,
                          I8888888888888888 _________          ,8888888888888b
                __________`Y88888888888888P"""""""""""baaa,__ ,888888888888888,
            ,adP"""""""""""9888888888P""^                 ^""Y8888888888888888I
         ,a8"^           ,d888P"888P^                           ^"Y8888888888P'
       ,a8^            ,d8888'                                     ^Y8888888P'
      a88'           ,d8888P'                                        I88P"^
    ,d88'           d88888P'                                          "b,
   ,d88'           d888888'                                            `b,
  ,d88'           d888888I                                              `b,
  d88I           ,8888888'            ___                                `b,
 ,888'           d8888888          ,d88888b,              ____            `b,
 d888           ,8888888I         d88888888b,           ,d8888b,           `b
,8888           I8888888I        d8888888888I          ,88888888b           8,
I8888           88888888b       d88888888888'          8888888888b          8I
d8886           888888888       Y888888888P'           Y8888888888,        ,8b
88888b          I88888888b      `Y8888888^             `Y888888888I        d88,
Y88888b         `888888888b,      `""""^                `Y8888888P'       d888I
`888888b         88888888888b,                           `Y8888P^        d88888
 Y888888b       ,8888888888888ba,_          _______        `""^        ,d888888
 I8888888b,    ,888888888888888888ba,_     d88888888b               ,ad8888888I
 `888888888b,  I8888888888888888888888b,    ^"Y888P"^      ____.,ad88888888888I
  88888888888b,`888888888888888888888888b,     ""      ad888888888888888888888'
  8888888888888698888888888888888888888888b_,ad88ba,_,d88888888888888888888888
  88888888888888888888888888888888888888888b,`"""^ d8888888888888888888888888I
  8888888888888888888888888888888888888888888baaad888888888888888888888888888'
  Y8888888888888888888888888888888888888888888888888888888888888888888888888P
  I888888888888888888888888888888888888888888888P^  ^Y8888888888888888888888'
  `Y88888888888888888P88888888888888888888888888'     ^88888888888888888888I
   `Y8888888888888888 `8888888888888888888888888       8888888888888888888P'
    `Y888888888888888  `888888888888888888888888,     ,888888888888888888P'
     `Y88888888888888b  `88888888888888888888888I     I888888888888888888'
       "Y8888888888888b  `8888888888888888888888I     I88888888888888888'
         "Y88888888888P   `888888888888888888888b     d8888888888888888'
            ^""""""""^     `Y88888888888888888888,    888888888888888P'
                             "8888888888888888888b,   Y888888888888P^
                              `Y888888888888888888b   `Y8888888P"^
                                "Y8888888888888888P     `""""^
                                  `"YY88888888888P'

closed account (3hM2Nwbp)
158.
lnk2019 wrote:
157. Leaving an ASCII Panda porn in your comments to annoy the next intern who will have the misfortune of working with your code.


PS. Nice Panda
Last edited on

159. don't volunteer or do more work than you can handle.
160. don't assume you can handle more work


( No wonder I get nothing done :D )
Last edited on
closed account (z05DSL3A)
156. add copyright to your files

a Programming sin? but anyway, in the UK at least, the code has copyrights automatically without the need to add a notice to it. If you didn't want it to have IP rights you would have to explicitly relinquish them.
Grey Wolf wrote:
a Programming sin? but anyway, in the UK at least, the code has copyrights automatically without the need to add a notice to it. If you didn't want it to have IP rights you would have to explicitly relinquish them.
Then we're all living in sin! :D
161. ill-defined copy-semantics for an object (the worst of which is falling back to the default copy-constructor generated by the compiler by accident)

should an object do a shallow-copy or a deep-copy for an object?
or should copying be disallowed via private methods?

if these policies are not clearly defined, it's very easy to segfault when using these objects in STL
Last edited on
162. failing to implement a proper strictly-less-than operator() on your class while using that class as a key for stl map or stl set

doing so will lead to all sorts of unspeakable run-time evils
closed account (S6k9GNh0)
163. Taking someones hard and well-deserved work and calling it your own for the e-peen.
164. Not immediately putting a delete after every use of new.
@QWERTYman, you're forgetting smart pointers..

@computerquip, aren't we floating away from the "programming" part of the thread's title?

@kfmfe, in debug mode, isn't it always asserted that if a < b, b is not < a? I'm sure I had problems with that.. Or is this what you meant by unspeakable evils?
suppose you had two data variables in MyClass, two ints, m_x and m_y - just right off the top of my head, I might try:

1
2
3
bool operator<( const MyClass& rhs ) const {
  return m_x<rhs.m_x && m_y<rhs.m_y;
}

finding all sorts of strange behavior when I insert into or search a map, I try this instead:

1
2
3
bool operator<( const MyClass& rhs ) const {
  return m_x<rhs.m_x || m_y<rhs.m_y;
}

turns out that this doesn't work, either! By now, I realized that I have stepped into some C++ doo-doo and need to think carefully how to implement strictly-less-than.

In the specific case I was trying to implement, I was playing with a couple of enums, which obfuscates the issue a little bit more.

Something seemingly obvious turns out to be not so obvious after all...
(not the first or the last time this has happened in C++)

edit: I thought I wouldn't give away the solution here in this thread - I'm sure there are several ways to do it right, but one way I found that worked can be seen in this thread, if anyone needs ideas:

http://www.cplusplus.com/forum/beginner/44785/
Last edited on
Mathhead200 wrote:
Why don't other languages have package private members? Screw friends!

The D Programming Language certainly has package level protection:

http://www.digitalmars.com/d/1.0/attribute.html
Last edited on
@kfmfe, I meant that if I have code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <set>

struct Silly{
   int x, y;

   Silly(int x, int y) : x(x), y(y) {}

   bool operator < (const Silly& s) const{
      return x < s.x || y < s.y;
   }
};

int main(){
   std::set<Silly> s;
   s.insert( Silly( 1, 2 ) );
   s.insert( Silly( 2, 1 ) );
   return 0;
}

I get " Debug Assertion Failed! <...> Invalid operator < ".
This works fine with && though, so I see your point.
165. Hopping on the newest technique
166. Not hopping on the newest technique
Hah! I only hop with one foot on the newest techniques!

-Albatross
Pages: 1... 4567