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?