Use of Correct indentation - Eclipse

Posted by goo on 14-Feb-2018 10:32

I am a big fan of using correct case, expand keywords and indentation, but for the Indentation I would love to have it in another way, is that possible?

I get:

  FIND FIRST hendelseRSTO NO-LOCK WHERE hendelseRSTO.ans#    = hendelse.ans#
    AND hendelseRSTO.son_aar = hendelse.son_aar
    AND hendelseRSTO.son_lnr = hendelse.son_lnr
    AND hendelseRSTO.Jour_lnr = hendelse.hend_lnr
    AND NOT hendelse.Slettet NO-ERROR.

I would love:

  FIND FIRST hendelseRSTO NO-LOCK WHERE hendelseRSTO.ans#    = hendelse.ans#
                                                                       AND hendelseRSTO.son_aar = hendelse.son_aar
                                                                       AND hendelseRSTO.son_lnr = hendelse.son_lnr
                                                                      AND hendelseRSTO.Jour_lnr = hendelse.hend_lnr
                                                                      AND NOT hendelse.Slettet

                                                                 NO-ERROR.

Is it possible ?

All Replies

Posted by Scott Riley on 14-Feb-2018 12:49

You can get hold of an old Progress program called beauty.p and modify it to indent anyway you like.

Personally I would indent like this:

FIND FIRST hendelseRSTO  WHERE

   hendelseRSTO.ans#       = hendelse.ans# AND

   hendelseRSTO.son_aar  = hendelse.son_aar AND

   hendelseRSTO.son_lnr   = hendelse.son_lnr AND

   hendelseRSTO.Jour_lnr  = hendelse.hend_lnr AND

  NOT hendelse.Slettet

  NO-LOCK NO-ERROR.

Posted by Stefan Drissen on 14-Feb-2018 14:27

religious war time! :-)

obviously you want:

FIND FIRST hendelseRSTO

  WHERE hendelseRSTO.ans#    = hendelse.ans#

  AND hendelseRSTO.son_aar = hendelse.son_aar

  AND hendelseRSTO.son_lnr = hendelse.son_lnr

  AND hendelseRSTO.Jour_lnr = hendelse.hend_lnr

  AND NOT hendelse.Slettet

NO-LOCK NO-ERROR.

1. an indent should only ever be ONE tab

2. AND / OR as query predicates determine the query - an AND at the back is like a Borat NOT joke.

Posted by goo on 14-Feb-2018 14:35

Stefan, I have to agree with you here :-)  but How to get it like that in eclipse?

Posted by Sanjeva Manchala on 14-Feb-2018 23:52

Hi,
 
At present we don’t have any option to customize code Indentation from Developer Studio. We are actively picking highest voted ideas from communities to improve Developer Studio experience. Please submit an Idea in communities if you really want to have this feature in Progress Developer Studio.
 
Hope this helps,
Sanjeev
 

Posted by slacroixak on 15-Feb-2018 02:20

My way is close to Stefan's but with NO-LOCK as early as possible

I wish it would be possible to align stuff to the right side of the WHERE word and the equal sign like in for an ASSIGN statement

   Perhaps I should revise my standard to dedicate a last line for the NO-ERROR

FIND FIRST hendelseRSTO NO-LOCK

    WHERE hendelseRSTO.ans#     = hendelse.ans#

    AND   hendelseRSTO.son_aar  = hendelse.son_aar

    AND   hendelseRSTO.son_lnr  = hendelse.son_lnr

    AND   hendelseRSTO.Jour_lnr = hendelse.hend_lnr

    AND   hendelse.Slettet      = FALSE NO-ERROR.

By the way, the following is bad for performance because progress cannot pickup an index for this:

 AND NOT hendelse.Slettet

people should do this:

 AND hendelse.Slettet = FALSE

Kind regards

/S

Posted by Scott Riley on 15-Feb-2018 02:46

hendelse.Slettet = FALSE is not the same as NOT hendelse.Slettet

Posted by James Palmer on 15-Feb-2018 03:26

Technically you are right, Scott, but anyone who relies on the unknown value of a logical deserves to be shot ;) M Lacroix is correct in saying that using equality is more efficient than using NOT though.

All examples above are incorrect because of the 'find first' though... ;)

Posted by Patrick Tingen on 15-Feb-2018 03:34

@james: correct. Didn't Tom suggest to change 'FIND FIRST' to 'FIND ANY'?

Posted by Scott Riley on 15-Feb-2018 03:40

I use find first myself but I've forgotten why! I've been using it for nearly 30 years.

In the back of my head I've a half-notion of it being quicker.

I couldn't justify it now but it hasn't bitten me on the bum either in all that time.

Posted by James Palmer on 15-Feb-2018 04:02

find first is fine if you genuinely couldn't care which record you get if there are multiple. I suppose it's fine if you're searching on a unique index (although that might change in future). The point of find without the first is that if you have multiple results satisfying the where clause you handle that and inform the user that something is wrong rather than making an assumption. I always used find first before, and likewise was never bitten. BUT, having changed my ways to omit the first I have encountered a number of situations where I /could/ have been bitten.

Posted by goo on 15-Feb-2018 04:28

OK, but should I use a FOR FIRST instead?

Sendt fra min iPhone

15. feb. 2018 kl. 11:03 skrev James Palmer <bounce-jdpjamesp@community.progress.com>:

Update from Progress Community
<4U3LU3OEGM9Z-jpg_2D00_70x70x2-jpg>
James Palmer

find first is fine if you genuinely couldn't care which record you get if there are multiple. I suppose it's fine if you're searching on a unique index (although that might change in future). The point of find without the first is that if you have multiple results satisfying the where clause you handle that and inform the user that something is wrong rather than making an assumption. I always used find first before, and likewise was never bitten. BUT, having changed my ways to omit the first I have encountered a number of situations where I /could/ have been bitten.

View online

 

You received this notification because you subscribed to the forum.  To unsubscribe from only this thread, go here.

Flag this post as spam/abuse.

Posted by James Palmer on 15-Feb-2018 04:31

For first will still mask the fact there are multiple results to a query. And is, in fact, even harder to mitigate against. find customer where... will not have a record available and you can test for ambiguous if none is available. You immediately know either your query is wrong, or your data is wrong.

Posted by Scott Riley on 15-Feb-2018 04:51

The advantage of FOR FIRST over FIND FIRST is the ability to use the FIELDS phrase.

But as James says, probably best to omit the FIRST.

Posted by ChUIMonster on 15-Feb-2018 05:21

We probably need a thread devoted to the evils of FIRST.

999 times out of 10 it is being used without any thought by a programmer who either thinks it is required because they have never seen a FIND without it or because they once thought they heard that it was faster and faster is always better.

For the record: FIND FIRST is only faster if it is also wrong.  If FIND FIRST makes your code faster it is because you do not have a unique index to go with your WHERE clause.  If you do not also have a loop and some FIND NEXT statements then you are ignoring the rest of the result set.  That means that you are violating 3rd normal form.  Either you are saying that the  FIRST record has a magical attribute that the 2nd, 3rd etc do not or you have redundant data.  If OTOH you do have NEXT statements then one has to wonder why you are not using FOR EACH?

The overwhelming majority of FIND statements do not need and do not benefit from FIRST.

Some FIND FIRST statements are subtle bugs that will probably never be tracked down and will intermittently bother users forever.

A small number of FIND FIRST bugs are catastrophic.  But still very hard to uncover.  Especially when nearly every FIND has a specious FIRST glued onto to it.

FIND FIRST everywhere is a bad coding habit.  Don't copy bad code.

Posted by goo on 15-Feb-2018 05:22

Thanks James, I will then stop using find FIRST &#128522; and it seems like I have to stop using …. NOT table.myLogicalField as well and continue with …. Table.myLogicalField = FALSE
 
//Geir Otto
 

Posted by ChUIMonster on 15-Feb-2018 05:34

FOR FIRST is even worse.

Try this with EACH and then replace EACH with FIRST:

for EACH customer no-lock where discount > 10 by discount:

 display cust-num name discount.

end.

If you expected that result for FIRST I'd be interested in how you would explain it to a user.

Posted by ChUIMonster on 15-Feb-2018 05:36

It is not possible to post good looking code examples on communities :(

And you are still using FIRST.

Posted by goo on 15-Feb-2018 05:38

Thanks, nice to know that I have done BIG mistakes the last 25 years &#128522; ok, now I know better and will NOT BE USING FIRST with my FIND &#128522;
 
//Geir Otto
 

Posted by Scott Riley on 15-Feb-2018 05:46

Please be aware that there are valid reasons to use a find first - it's not always wrong as has been suggested.

Say you have an accounts package and you want to display the oldest outstanding transaction for an account in an enquiry.  

You can do a find first on the transaction table for the account where the status is open using an index that contains account, status and transaction date.

Posted by slacroixak on 15-Feb-2018 06:04

I believe I thought of the unknown value and that I was technically right.

Try with this:  Did I really miss something?

DEFINE TEMP-TABLE hendelse NO-UNDO

       FIELD Slettet  AS logical

       INDEX Slettet  Slettet.

CREATE hendelse.

hendelse.Slettet = ?.

VALIDATE hendelse.

FIND FIRST hendelse WHERE NOT hendelse.Slettet NO-ERROR.

MESSAGE AVAILABLE hendelse

  VIEW-AS ALERT-BOX.

Posted by ChUIMonster on 15-Feb-2018 06:20

Of course it's not ALWAYS wrong -- just 999 times out of 10 ;)  Finding a few cases where it is ok does not make it valid to glue FIRST onto every FIND.  THAT behavior is what I claim is ALWAYS wrong.  It is NOT appropriate to ALWAYS code FIND FIRST.

Posted by Peter Judge on 15-Feb-2018 08:08

The easiest way to post pretty code is to reply via email with HTML email; then paste your ABL from PDSOE (which keeps the formatting) . Note that this only works with lower-case code.
 
   
    /** Returns a byte at the specified position, and increments the
        position marker.
       
        @param int64 The position at which to return the byte.
        @return integer The byte value at the current position */
   
    method public integer GetByte(input piStartPos as int64):
        define variable iStartIndex as integer no-undo.
        define variable iGetFrom as integer no-undo.
 
 

Posted by Tim Kuehn on 15-Feb-2018 08:34

The only valid uses for FIND FIRST is if you know there's a number of records with values that match the WHERE criteria, and you're ok with that. 

Say you're checking OrderLine to see if any records exists for an Order.OrderNum. In that case a structure like this

FIND FIRST OrderLine 
    WHERE OrderLine.OrderNum = Order. OrderNum 
    NO-LOCK
    NO-ERROR
   .

is appropriate. 

Another example is the question of whether any of the OrderLine records for an Order have been processed - 

FIND FIRST OrderLine 
    WHERE OrderLine.OrderNum = Order. OrderNum  AND 
                  OrderLine.isProcessed = TRUE
    NO-LOCK
    NO-ERROR
   .

also is appropriate. 

What isn't appropriate is something like this - 

FIND FIRST OrderLine 
    WHERE OrderLine.OrderNum = Order. OrderNum  AND 
                  OrderLine.LineNum = 1
    NO-LOCK
    NO-ERROR
   .

because OrderLine.OrderNum,  OrderLine.LineNum is supposed to be unique for that table. If for some reason the OrderLine table got a duplicate Orderline, Linenum record a FIND FIRST would cover up that fact instead of failing spectacularly like it should.

Tim Kuehn

Posted by James Palmer on 15-Feb-2018 08:56

Although, to pick nits, in your examples in a client/server environment I would use can-find() because it doesn't pull the records across the network ;)

Posted by Tim Kuehn on 15-Feb-2018 09:10

@James - it all depends on your use-case. If you want to check for the existence of a condition then CAN-FIND is better. If you need a value from one of the records, then FIND is required. 

Posted by Thomas Mercer-Hursh on 15-Feb-2018 09:35

To reinforce what Tom has said ... this being an area where we agree! ... one of the key bad things about FIND FIRST is not so much that the program will behave incorrectly as what you are communicating to any future developer who has to deal with the code (which might be you, 10 years later, when you have forgotten everything about the code.  If you find the first record in a group and treat it specially, then you have violated normal form.  So, CAN-FIND is fine because you are merely determining whether a given set is null or not and you don't care about the count as long as it is not zero.  But, the minute you so much as use a value from the record which happens to come first, you are treating that record as special and are violating normal form.  Storing something in it is even worse.

And, if the specified criteria are sufficient to uniquely identify a record, so the issue about one of  a set does not exist, then using FIND FIRST communicates to the later programmer that there is a set, which is not true.

This thread is closed