× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




Regexs can undoubtedly be complicated, but I really don't follow your argument at all:

exec sql set :dollars = regexp_substr(:source, '(\d{1,2}\.\d{2})\~$',1 , 1, 'i', 1);

really is one line of code.

This has nothing to do with trying to be a smart-arse, IMO the above solution has a couple of advantages, not least of all its flexibility and the fact you can soft code the pattern and look it up at run time, so if your spaghetti of %scans, %trims, %substrs doesn't work properly, you missed a scenario or an unanticipated data format comes in, it can be a simple case of tweaking the regex pattern and you're up and running, instead of having to make a program change.

I think the argument about such techniques being "hard to understand and modify" is also specious. The above code is fully documented, in the SQL manual and the REGEX docs, one just has to read them. Regexs can also easily be tested, and explained, with sites like https://regexr.com/

Tim.



________________________________
From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> on behalf of DPC Marion <DPCMarion@xxxxxxxxxxxxxxxxx>
Sent: 31 July 2020 21:43
To: 'Midrange Systems Technical Discussion' <midrange-l@xxxxxxxxxxxxxxxxxx>
Subject: RE: How to get the dollar value from this text string?

I personal cannot stand "multi-line" one liners. I really cannot stand to see a one liner that is 5 screen shots long in a program that blew up at 2:00 in the morning in a mission critical program. How do you quickly debug it, fix it and get the production box working again in minimal time.
Not something I want to see when I get a call out of bed to fix a problem.

Yes, these one liners are neat to be able to do, but they do not allow for a quick debug and fix solution. Many programmers code stuff a particular way because they can. I used to be proud of how much I can do on a single "line" of code, until I had to modify other's programs. I learned it is better to break things up into smaller sections.

It is important to think about the other programmers that will be modifying your code in the future. How easy is it to understand and modify?

In my work estimates, If I see an embedded SQL RPG program, I increase the estimated time. Particularly for programs that are joining tables with sub tables, etc.

If the programmer coded it in smaller sections, it would be easier to debug, modify and fix.

Just saying.

Rich M.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.