J.Pluta
Okay, I admit to being biased because this is showing up in RGP Developer, but this really is some cool code. The code itself is pretty impressive, showing how RPG can be just as powerful as any other modern language in developing complex algorithms. At the same time, I really enjoy some of your syntactical conventions, especially the consistent application of long name syntax in the D-sepc (the ... notation) even when the names aren\'t long. I think RPG programmers can take a good look at this and see how a sense of style can make your free-form RPG look really good. Joe
H.Boldt
Adam wrote: "[i>Ever been jealous of your Perl programming colleagues with their built-in hash tables? Learn how to make your own using RPG![/i>" Let\'s see how the example looks in Perl. I don\'t think Perl programmers will ever be jealous of their RPG colleagues. Cheers! Hans
[size="1">Code[/size>
H.Boldt
Oh yeah, here\'s the same coded in Python. Cheers! Hans
[size="1">Code[/size>
adamglauser
Hi Hans, Of course it will always be easier and nicer to use hashes in a language with direct support for those constructs. However, IMO there are situations where such constructs would be useful in RPG, and having a less easy to use version is better than none at all. At the very least, it can be a good exercise to do something like this in RPG, if only to get thinking outside of our usual RPG paradigms.
Guest.Visitor
Hans, The point is, nobody at this jobsite uses, Python, or Perl but we control billions of dollars with RPG. If we wanted to know how to do this in either, we would Google it. Adam, thanks, for helping us push the RPG envelope. This is what I am talking about, bring it on. Let\'s take RPG where its never been before.
H.Boldt
Adam: Did you consider implementing these functions using the independent index MI instructions? Cheers! Hans
H.Boldt
Craig: I know few people here use Perl or Python. Since the System i is a premium priced platform, compiled languages will always have the edge. That is, if you\'re spending 6-7 figures on your computing hardware, you want to make sure your CPU\'s are running at least at 90% (or more), with apps tuned to achieve stringent performance goals. On the other hand, if a shop is spending more money on its programming staff than on its hardware, then programmer productivity becomes more important that machine performance. Interpreted languages like Perl and Python offer IT shops much much higher programmer productivity, as well as much faster response time to change requests. Regarding library functions like Adam\'s hash table functions, does this really "[i>take RPG where its never been before[/i>"? I don\'t think so. To me it just highlights the sorry lack of functionality in the language. To make best use of the language, you need to be intimately aware of the System i API\'s and MI built-in\'s. But in doing so, your apps are also forever tied to that one hardware platform. Now it may well be a fine piece of computing hardware, but your choices will always be limited to this one niche. Cheers! Hans
Ralph Daugherty
Adam, I downloaded your code. Thanks. It is really excellent programming, not only substance, but style and completeness. I have never had occasion to use functionality like this or other class library type code in my business programming through the years, but when I do there couldn\'t be a better model of open source support for it than this. regards, rd
Ralph Daugherty
Hans, I disagree with much of what you said, but the only issue worth discussing that honors Adam\'s article is that of native support for functionality, functionality such as he has written here. First, let\'s describe native support. When the PHP authors or addon authors want to add native support for a function, say the function that Adam just wrote, they write a C module to compile in the PHP interpreter. That\'s significant in that it is now a part of the language to call that runs at native speed, versus functionality provided in PHP script to be interpreted. The C code is compiled, and of course the C compiler for that machine uses native API\'s. For example, PHP was compiled for i5/OS by Zend. Compiling the C code for the PHP engine that provides native support for PHP language functions makes it no more tied to i5/OS than Linux or Windows. Now, let\'s add Adam\'s functionality to RPG as native support. We compile it into a service program. The functionality is callable from RPG with similar syntax to other languages. It runs at machine speed as does compiled C. The MI stuff is such a crappy red herring it is laughable. Just as C library functions and Java library functions are added to the language, RPG library functions are added in exactly the same way. Native support is only an issue with script languages you are so fond of, and even then the script language authors provide add on capability to add compiled library functions for native support, necessary for script languages. So to bash RPG for lack of native function support is to bash C or any language for lack of native support, except guess what, we have native support for all that C has, and can add anything from a script language if we wanted to. Quite frankly, we didn\'t need it. If it\'s useful, we\'ll add it. And it will be just as native as anything added to a script language. rd P.S. I am starting a major project for my web site in PHP, and acquired Zend Studio, so there are places PHP is the right solution, that being running on my web site hosted on a Linux server. Will I develop it faster and better than I do in Java or RPG? Nope.
H.Boldt
Ralph wrote: "[i>there couldn\'t be a better model of open source support for it than this.[/i>" I don\'t mean to nitpick, but is this really open source code? I am not a lawyer, but anyone wanting to use any code found on the internet really has to consult with a lawyer before using it. Here\'s my understanding of copyright law: The person who wrote that code owns the copyright to that code. By offering the code as part of an article to MCPressOnline, they now have certain rights to that code. But unless a license is explicitly given, others have no rights to use it. For this to be truly "open", license to use the code must be explicitly stated. Someone needs to consult with a lawyer to see who can grant those usage rights. Can MCPressOnline grant readers those rights? Or can Adam grant those rights? What exactly did Adam sign away when he offered up his code to MCPressOnline for publication? Cheers! Hans
Guest.Visitor
Hans, I have plenty of respect for your technical knowledge. I wouldn\'t debate too many technical aspects of any language with anyone, cause I would probably lose. I would stand on the sidelines and listen sometimes, if I thought I could learn something useful. And useful is the key. You write articles, write an article on it and those interested will read it, and maybe not many people will hijack it back to RPG. I fear that as soon anyone poo poos the solution offered in RPG, then productive conversation takes a back seat. But, I am in need of technical expertise that will help me solve business problems with the hardware and languages provided (approved by management) to me. Hans, we are tied to one niche, as much as possible, and we like it that way. I only apply to jobs that operate in that Zone, and I like it that way. Management here, actually reviews any new ways to do things that can be done by RPG programmers first, to help keep us productive and to help us career wise if we ever leave, imagine that. Because he understands that happy and productive programmers help the \'BUSINESS\'. He also, doesn\'t have to expand his shop to a dozen flavors of programmers either, or dread if that PHP or Perl programmer gets another offer somewhere else, then he has to scramble to find another exotic programmer that also understands \'BUSINESS\'. Hans, I would find it refreshing if you took on a challenge. For the next dozen technical articles written, expand upon the RPG or OS/400 technical possibilities of the article to help us enhance our companies \'BUSINESS\'. Help us, with your technical knowledge, take RPG where it hasn\'t been before. Hans, help me work with the tools I have.
JonFParis
I\'d love to take a look at the code associated with this article - but the only reference to code that I can find is in this discussion thread! Where\'s the link to the download? I have been over and over the article from top to bottom and can\'t see it anywhere.
Ralph Daugherty
Hi Jon, the last word in the article "here" is underlined as a link. It\'s a download link. rd
Ralph Daugherty
Hi Hans, I didn\'t mean the open source code would be distributed in this fashion. This code of course is for discussion purposes and the author states he welcomes code enhancements. Our open source RPG code would be distributed through a project on SourceForge or the like, or in a change control repository like CVS or Subversion or in an FTP directory on a personal server. Code that we write as infrastructure examples should not be encumbered with a license but done just as Adam did it, perhaps with a "For educational purposes" statement in the header. We should want to disseminate RPG code with best practices examples widely with no restrictions so business can use and incorporate freely without lawyers involved. Of course code that is translated from open source with a license needs to retain the license. We need a lot more good code examples out there so people can use as a base with best practices, such as Adam\'s displays. rd
nandelin15
Adam, Your hash table service program is an excellent example of how RPG can be extended in ways that many programmers would never think of. I just wish there were a definitive repository for things like this, which encouraged contributions of RPG extensions and open-source development. One that comes to mind is www.easy400.net. Your article spoke of "collision" as something that degraded performance and I wondered if you or one of the other computer scientists here would care to explain the problem in more detail. I gather that collision has something to do with indexing or searching an array. It appeared to me that quite a bit of code in your service program was dedicated to minimizing it. Thanks, Nathan.
adamglauser
Thanks for asking about collisions Nathan. Upon rereading that section of the article, I didn\'t explicitly say what constitutes a collison. A collision can occur when an item is added to the dictionary. When the program maps the key value to an array index, it may happen that the array already has an item at that location. The article describes in general a couple of approaches to handling these collisions. The nice thing about hash tables is that if there are no collisions, the time taken to add, remove, or retrieve an element stays near constant as the number of elements in the hash table increases. In computer science lingo, we say the time complexity of the operations is O(1). See the Wikipedia article on big-O notation for more info on what that\'s all about. If you think about it a bit, this is makes sense - you don\'t need to search through the elements to figure out where to look for a particular element. However, if a collision occurs, you need to do some more processing to figure out where to put the element. Using the linear probing method in the code, we get (comparatively) very bad performance if the array is near full. To illustrate this, suppose you (very unwisely) choose a hash code function that returns 1 for any given key. Let\'s say we have an array of size 10 for our hash table. The array start out empty: o o o o o o o o o o When we add the first item, the hash code tells us we should put it in position 1. Now the array looks like: x o o o o o o o o o When we add the second element the hash code tells us we should put it in position 1. Since there\'s already something there, we check the next spot and find it empty, so now the array looks like: x x o o o o o o o o When adding the third element, we\'d have check position 1, position 2 position 3 before we can insert the element. If we carry this on, we can see that we have to check 1 extra time each time we add an element to the array. So the time for the add to complete increases linearly with the number of elements in the array. In other words, we now have an add operation with O(n) complexity. I hope that clears things up a bit. Let me know if that made any sense to you.
Guest.Visitor
Copyright RPG source??? In other words writing something in any language for any purpose comes with an implied copyright? As if you could do anything when you see some code you wrote a few years ago for some private or public institution, and the company your with now just purchased a new "package" and while looking at some of the source, you recognize code and even comments you made way back when? Hey it happens all the time! Does it make me mad. Hell no. It\'s a source of pride that somebody thought your stuff was good enough to copy and now sell it or give it away as part of "packaged" software. Ask the guy who wrote "POP" for the S/36 about that issue. As a rule...If I include something somebody else wrote as-is or even modified, I always give credo\'s to the author, where I got it, and so forth. It\'s a matter of honor as well as pride.
Guest.Visitor
If you are an employee, everything you create as an employee is property of your employer? Why? Cause you signed a hiring agreement. Read the fine print. And if you are a contractor, everything you write for the client is property of your client, for the same reason. If you as a contractor state that the code will be your property, you simply don\'t get the contract. Now, if you work for a very small company, there is a small chance that you own the code you write because they don\'t mess with the red tape. Chris
adamglauser
[quote>In other words writing something in any language for any purpose comes with an implied copyright?[/quote> That\'s how I understand it. As if you could do anything when you see some code you wrote a few years ago for some private or public institution, and the company your with now just purchased a new "package" and while looking at some of the source, you recognize code and even comments you made way back when? Well, theoretically I think you could. Practically speaking, you\'re probably right. It would be difficult to take on a a large company on your own. FWIW, there have been cases in which open source projects have been in violation of their licenses, and cases have been pursued. From what I understand, there have been no cases that made it to court in the US. Recently, Monsoon Multimedia was sued by the SFLC on behalf of the developers of BusyBox. I believe they settled out of court. In Europe, it is my understanding that there have been decisions in favour of the GPL. I feel much the same way as you do - I\'ll be happy if people find my code useful. I agree with Hans that explicitly stating a license is a good idea. I\'ll have to discuss that with the MCPress folks.
SoftwareTrend
Unless contractors sign away their rights it is normally assumed that they own the intellectual property of their work. I\'ve seen a local instance here where a reasonably large app was written by a single contractor who ended up walking with the product. The irony was that the company thought they would save a fortune by hiring in a contracting slave to build "their" product and didn\'t bother to get someone in the legal profession to look over the agreement. I know first hand the character of their directors - they used to have an old s36 I used to have to look after. It couldn\'t have happened to nicer idiots. I do contract work for another company that ended up with this app in one of its subbranches. Interestingly, I have also never signed away any rights to the work I do at that site.
adamglauser
I didn\'t. For a start, I\'m haven\'t gotten in to MI programming at all. I\'d certainly be interested in learning more about this in the future. Can you give me a quick overview of what independent indices are all about? I did consider using a user space or something along those lines to facilitate auto-resizing and to avoid limiting the maximum number of elements. I decided it was better to focus on the core concepts, this is a TechTip after all, and then revisit such details if there was any interest.
H.Boldt
Craig: I understand fully what you\'re saying. As it is now, I don\'t have access to iSeries hardware since I\'m still between jobs. There just aren\'t that many iSeries shops hiring within a comfortable commuting distance, and I don\'t want to move. I suppose I could sign up for one of those iSeries time-sharing services. But unless McPressOnline pays significantly better for technical articles than the couple of IMHO articles I had published, there\'s still little incentive there. Still, if there\'s some money to be made, I should consider writing libraries with functionality useful for RPG programmers. I rather like the idea of being self-employed rather than "working for the man!" Craig, and others reading: If you have ideas for useful RPG related tools or function libraries that you\'d be willing to pay for, or RPG related technical articles, send your ideas to me at hans@boldts.net. Seriously. Yeah, I know I\'ve been hard on RPG and the iSeries lately. But honestly, I did enjoy working on them, and I would like to work with them again. Believe me - the iSeries is still a whole lot more pleasant to work with that the zSeries. I suppose deep down, I\'m still rather bummed out over the summer 2004 re-org that moved me out of the iSeries area at the Toronto Lab. Anyways, thanks for giving me something to think about. Cheers! Hans
nandelin15
Yes that makes sense, Adam. Performance would be better by minimizing the number of operations it takes to insert or retrieve an entry from a table. I studied accounting in college, so some of the low-level algorithms used in computer science are a bit of a stretch for me. I\'ve done some coding of linked lists in RPG; dynamically expanding and contracting lists as entries are added or deleted, but I don\'t recall ever creating an index to speed up retrieval. Thanks, Nathan.
Guest.Visitor
Yes, depends on the contract. But the client wields all the power. If they state that they will own the code, and you disagree, you don\'t get the contract. iSeries contractors that have bills to pay say sure, you own the code Mr client. Or the contract goes to someone else or overseas. I was an iSeries contractor for 11 years and *always* had to sign a contract that stated the client, not me, owned the code. So, if you own the code as you say, do these companies pay you royalities for using YOUR code? Do you have them sign a software license to use your code that you wrote for them? If so, do they comply with this? Chris
Please login to make comments.
User Rating: / 1
PoorBest 
   MC-STORE.COM