Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  A C++ program puzzle

Recently I came across a question asked by wang2191195 on a Chinese IT forum CSDN which asks about a C++ program puzzle. He has a code snippet which cannot be compiled. The code is:#include <cstdlib>#include <iostream>using namespace std;class Base{public: virtual void func(){ cout << "Base::func()" << endl; } virtual int func( int num ){ cout << "Base::func( int " << num << " )" << endl; return 0; }};class Derived : public Base{public: virtual void func(){ cout << "Derived::func()" << endl; ...

11,333 4       C++ OVERLOAD PUZZLE HIDE


  "Programmer" is an Overgeneralization

"Beware of bugs in the above code; I have only proved it correct, not tried it." - Donald KnuthEarlier today, I came across a post during a google-fu session that claimed that no one should use the C++ standard library function make_heap, because almost nobody uses it correctly. I immediately started mentally ranting about how utterly ridiculous this claim is, because anyone whose gone to a basic algorithm class would know how to properly use make_heap. Then I started thinking about all the programmers who don't know what a heap is, and furthermore probably don't even need to know.Then I reali...

3,722 0       PROGRAMMER OVERGENERATION OVERLOAD


  Don't Overload #nil?

There’s a popular post on Hacker News about writing confident code by, among other things, overloading Object#nil? and returning “null objects” instead of nil itself.DO NOT DO THIS.In Ruby, all objects (except nil itself) coerce to the boolean value true. Your object will be nil and true at the same time. Bad things will happen. Your coworkers will cry. Sad people from around the world will ask bewildering questions on your mailing list.Here’s what happens:1234567891011class NullObject def nil? true endendo = NullObject.newo.nil? #=>...

2,807 0       RUBY #NIL OVERLOAD OBJECT