You're teaching us what?

About Me

Thoughts on academic software engineering and how it applies to the real world. "Just because you teach it doesn't mean its right."
Home | Profile | Archives | Friends

Should OOP separate interface from implementation? - 10:49 AM, 9/8/2006

I have been thinking about this a lot, and I have come to conclusion that the benefit of OOP is that it combines the interface and the implementation. When done correctly, I only have one place to look for both. When done incorrectly (C++), I have my interface and implementation scattered across several files.

 

Of course, this line of thinking implies interface-heavy frameworks like J2EE are dead wrong. Perhaps that is why I find them so tedious and difficult to use.

Learning C++: The problem with setprecision - 12:54 AM, 9/3/2006

Today I’m learning about numeric formatting in conjunction with cout. In other, more sensible languages, you use functions or methods to format numbers.

In pre-OO languages, you usually have a format function. For example…

Format( x, "#.##")

Object orientated languages often offer formatting as a method on the number itself.

x.ToString("#.##")

In C++, which could support both styles, choose something else entirely.

cout << setprecision(3) << x;

Instead of creating a string from x like the other examples, setpercision modifies the internal state of the stream. Since cout is a globally accessible stream, this is a very bad thing.

 

In order to use cout safely, you need to always call setpercision immediately before passing it any floating point value. The reason for this is that you have no other way to know what the precision currently is. Any function call, even one that doesn’t write to the stream, could potentially change the precision.

 

This function has a subtle flaw, it doesn’t restore the precision for the stream. Since using cout for debugging is a common practice, this error can occur in any function. And it can be introduced at any time long after the original code is tested and released.

 

float addValues(float a, float b)
{
 cout << setprecision (5);
 #ifdef _DEBUG
  cout << "A: " << a << endl; 
  cout << "B: " << b << endl; 
 #endif
 return (a+b);
}

There is a way to safely use setprecision, but it requires some book keeping.

float addValues2(float a, float b)
{
 #ifdef _DEBUG
  streamsize original = cout.precision();
  cout << setprecision(4);
  cout << "A: " << a << endl; 
  cout << "B: " << b << endl;
  cout << setprecision(original);
 #endif
 return (a+b);
}

Another problem with set precision is that it isn’t a general solution. You can only use it when dealing with streams. If you want to use the value somewhere else, say in a GUI window or a database field, you have to find another technique. Compare this to the earlier examples, which could be used wherever a string is valid.

 

Now lets take a look at the definition for setprecision. The first thing I look at is the return type. According to the MS docs, “Return Value: The manipulator returns an object that, when extracted from or inserted into the stream str, calls str.precision(_Prec), and then returns str.”

 

Well that doesn’t really tell me anything. Maybe a web search will be better. The web site CPlusPlus.Com says…

“Return Value.
  Unspecified.
  This function should only be used as a stream manipulator.”

Yea, that’s real helpful. Maybe there is something of use in the header file.

_MRTIMP2 _Smanip __cdecl setprecision(streamsize);

To the novice (i.e. me), it looks like this function has three return types. Obviously this cannot be possible, so let’s examine them one at a time to try to figure out what it happening.

 

First off is _MRTIMP2. Well that identifier sure doesn’t give any clues as to what it means, but maybe we can find more info if we check its definition.

#define _MRTIMP2

Well who would have guessed that you can define a token as nothing? Gee, that seems really useful. Maybe I should decorate some other code with _MRTIMP2 just to confuse anyone who might steal my source code.
 
Next up is _Smanip. Just like its counter-part _MRTIMP2, the name tells me absolutely nothing. Of course the header file is full of useful information like _Manarg is the argument value.

  // TEMPLATE STRUCT _Smanip
template
 struct _Smanip
 { // store function pointer and argument value
 _Smanip(void (__cdecl *_Left)(ios_base&, _Arg), _Arg _Val)
  : _Pfun(_Left), _Manarg(_Val)
  { // construct from function pointer and argument value
  }

 void (__cdecl *_Pfun)(ios_base&, _Arg); // the function pointer
 _Arg _Manarg; // the argument value
 };

A look at the index for _Smanip doesn’t turn up anything direct, though one page does mention using it to create custom stream manipulators. Maybe that stands for “Stream MANIPulator”.

 

Well at least it is a type, which just leaves us with one mystery, __cdecl.

 

Turns out this is a Microsoft-specific keyword. The docs say “This is the default calling convention for C and C++ programs.”. Well, if it is the default, then why was it explicitly specified?

 

Now that the return type is known, we can look at the arguments. In this case there is only one, and it is of type streamsize. Fortunately this one is easy to figure out from the header.

#ifdef _WIN64
typedef __int64 streamsize;
#else /* _WIN64 */
typedef int streamsize;
#endif /* _WIN64 */

Now that seems like an odd choice to me. According to Wikipedia, a double precision floating point number has about 16 decimal places. That means even a single byte is more than sufficient to store this information. So why it is potentially stored as a 64-bit number?

 

Apache vs. Yaws – Do you really expect me to believe this? - 11:41 PM, 9/2/2006

It was suggested that I check out this comparison between Apache and Yaws. Supposedly this is proof that Yaws, which is based on Erlang, is better than Apache.

http://www.sics.se/~joe/apachevsyaws.html

 

What I noticed…

Machine 2 requests 20 KByte pages from machine 1. It does this in tight a loop requesting a new page as soon as it has received a page from the server. From this we derive a throughput figure, which is plotted in the horizontal scale on the graph. A typical value (800) means the throughput is 800 KBytes/sec.

So only one page was ever requested, and it was pretty small at that. Most pages and all images I normally deal with are larger than that. Important issues such as cache misses don’t really come into play when there is only one file. Thus this is not a realistic scenario.


Apache dies at about 4,000 parallel sessions. Yaws is still functioning at over 80,000 parallel connections.

What does it mean to die? Did the server crash? Did it just stop accepting new requests?

 

Why did it die? Was there an undetected memory leak? Did the backlog of unprocessed requests cause an out of memory situation?

 

We believe that this effect will be even more dramatic in other operating systems and especially so in systems which generate dynamic content. A performance difference of one to two orders magnitude would not surprise us.

Where is the follow-up that tests this hypothesis?

 

If you want me to believe something, then you need to do your due diligence. One graph from a contrived test isn’t enough.

 

Sure, we are CMM level 7 - 5:28 PM, 8/8/2006

In my career, both professional and academic, CMM is occasionally mentioned. For those who don’t know, CMM is the Capability Maturity Model, a certification offered by the Carnegie Mellon Software Engineering Institute. Without it, a company cannot get many government contracts.


CMMI has three problems.


First, it is very expensive. Most companies cannot afford the $100,000 it costs for an assessment. This leaves many smaller, more effective companies unable to compete for contracts.


Secondly, it is rife with fraud. Since the measurements are subjective, it is easy to bribe assessors and simply buy their certification. However, it appears that most companies don’t even bother to spend that much time. They simply say they are CMM level 5. What choice do they have when it’s required just to play the game?


For more information on this, see this article in CIO Magazine.
http://www.cio.com/archive/030104/cmm.html


Finally, it probably doesn’t work.


When CMM was created, many of it theories were untested and now it’s too late. Carnegie Mellon has no vested interested in proving whether or not CMM is effective. If they do conduct a fair study and find that CMM isn’t effective, they lose creditability and the lucrative certification market.


Even worse, the companies that use CMM are not concentrating on improving their code quality. Rather, they are concentrating on maintaining and improving their CMM level. In my experience, CMM distracts from real development efforts.


While CMM is a political curiosity, it shouldn’t be taught in schools until independent studies demonstrate that it really is effective.


P.S. The only study I have seen mentioned is that of Reasoning, which found that CMM level 5 companies averaged more defects than anyone else. Unfortunately, I don’t have access to that report myself.

http://www.softpanorama.org/SE/CMM/index.shtml

 

Why Open Source is not for me. - 10:33 AM, 6/28/2006

The problem I find with open source is that there is no hard incentive for them to fix bugs. And since the bugs in their code aren’t getting fixed, my applications don’t work.

 

Take Indy Sockets for example. Since April of 2005 there has been an open bug report about the Date header in outgoing emails being incorrect. It is not June of 2006 and there has still been no work on the project. This is an important issue, and should be easily fixed. So why hasn’t anyone stepped up to the plate?

 

I think the underlying problem is that open source programmers are not professionals. Sure they may be professionals in their day jobs, but any open source project is just a hobby. Since they don’t charge for it, I cannot offer them money for an upgrade. And by the same token, I cannot threaten to withhold payment or sue. With no stick and no carrot, no work gets done.

 

Before anyone starts down the idealized path, no, I cannot fix it myself. I don’t have ready access to a Delphi compiler. And even if I did, I would still have teach myself the language before I could even start. I haven’t used Pascal in years, so it will take quite some time to get up to speed. And my project needs to be fixed by close of business.

 

The peaceful dream of open source has become my waking nightmare.

 

 

Login | Browse Blog Directory | Free Blog Hosting Blogger Team - Start Your Own Blog