Thursday, November 25, 2010

A simple generic template function

A simple generic template function for getting the minimum and maximum from STL container and simple arrays.

Nothing too complicated, I just liked this example.

1:  template<class Iterator>
2: pair<Iterator, Iterator> minMaxFinder(Iterator begin, Iterator end)
3: {
4: Iterator min = begin;
5: Iterator max = begin;
6: for(++begin ; begin != end; ++begin) {
7: if(*begin > *max) {
8: max = begin;
9: }
10: else if(*begin < *min) {
11: min = begin;
12: }
13: }
14: return pair<Iterator, Iterator>(min, max);
15: }
16: int main()
17: {
18: int iArr[] = {15, 5, 70, 2};
19: pair<int*, int*> minmax = minMaxFinder(&iArr[0], &iArr[4]);
20: cout << *minmax.first << ", " << *minmax.second << endl;
21: list<string> sList;
22: sList.insert(sList.end(), "small");
23: sList.insert(sList.end(), "smallish");
24: sList.insert(sList.end(), "big");
25: sList.insert(sList.end(), "biggish");
26: pair<list<string>::iterator, list<string>::iterator>
27: minmaxS = minMaxFinder(sList.begin(), sList.end());
28: cout << *minmaxS.first << ", " << *maxminS.second << endl;
29: return 0;
30: }


Code formatted with http://codeformatter.blogspot.com

Monday, November 22, 2010

Thoughts on Open Source licenses, Patents on Software and such

I'm dealing with Open Source usage approval cycle, which is an important task in any company, last thing that you want is to have your developers use whatever they find on the web.

Few insights and thoughts from my experience:

  • Developers in genral are mostly ignorant to legal issues. If not controlled they may use a free 30-days evaluation copy embedded in their system, just because the word free appeared somewhere in the site. In most cases they don't bother to read the license.
  • With Off-Shore developers problem is even bigger. They tend to be much more open with open source, without seeing the risks. Even if they do follow the company policy, submitting usage requests for open source usage, you may find inside their code much more "embedded" un-approved snippets and libraries. I tend to think that the reason is the distance, they believe that even if caught the maximum you could do is yell at them over the phone or in e-mails, but you cannot beat them physically and they use it.
  • For above reasons and others, usage of open source must be controlled. There are scanning tools in the market that help you find un-reported usage of open source and commercial external software. Usage of such is helpful in finding the disobedient developers who still drop in whatever they like, fix that on time and beat them while the felony is still hot.
  • Scanning tools also point at many usages that are a very small snippet of something that looks like might be taken from an open source or even from an un-licensed example on the web. To some it seem a problem that should be fixed in the code, I personally believe that the rights on how to perform quick sort do not belong to anybody, even if part of some open source or are published on the web somewhere. Taking two notes from a melody doesn't harm its rights.
  • Same goes for patents on software. Publishing a patent on algorithm is problematic, but many patents are on "a method and a system". I have such one myself. Does it really prevent anyone from creating a new similar development? Should it?

Monday, September 20, 2010

Resource Files

Programs interact with a user in many ways.
They write things to a screen, send messages over the network, say things aloud. And more.

In most cases, except maybe for debug logs, the string conveyed to the user shall be edited, and in some cases maybe even translated to other languages.

It's pitty to still see today modules that interact with a user, without using external resource files. Guys - how do you want someone to edit your lovely messages into something readable? and translate it into Swedish? or Yiddish?

The technical way of how to use resource file is a very old trick. The problem is that in the early days of a project, this is not the top prioirity (that's wrong, guys! the price at the beginning is very low!). The problem is that when it does become relevant, the code is full of strings in so many different places that it's a nightmare to do something.

Things to do on the first day when starting a new project (don't postpone it to "later"):
1. Use good logging mechanism (exiting one, don't invent the wheel)
2. Use automatic build mechanism
3. Use a resource file
( -- do you have more - please add as a comment!)

Well, wait I have one more - have a defined API (slash protocol slash wireframes) for the modules you are developing.