Post Reply 
epoch Prime
01-06-2018, 03:28 PM (This post was last modified: 01-06-2018 03:49 PM by pier4r.)
Post: #28
RE: epoch Prime
Little nitpick.

When one use constants, like 86400, at first it is ok to plaster them all over to get things done, but then (as you realized) a little typo may produce problems.

Disclaimer: I learned what I am going to write after having done, quintillions of times, the same actions I am going to criticize.

So a tip is: refactor them in (static) variables, maybe also with more than 2 letters for readability. When I see algorithms (especially long ones) that use quite unreadable names, while I appreciate the sharing effort since sharing is caring, I am not going to use them to understand what is going on. This because it is too much work to decode what they do if they are not commented and not easy to read. They are write only code.

I will do again my version unless I do not care what the algorithm is doing and I need only the result, then I will use the shared version.

Also comments (but comments are lacking in many algorithms seen in this forum so far, that's a pity). Comments documenting why such instructions are there, not how.

So something like:

Code:

//we can use up to 30 (!) chars in the variable names and function names.
LOCAL sec_in_day:=86400;
LOCAL sec_in_hour:=3600;
LOCAL unix_epoch_start_time:=1970.0101;

EXPORT epoch2date(epoch, zone)
//epoch
// - the number of seconds returned by the Unix timestamp
//zone
// - the timezone defined by the number of hours of difference from the UTC time.
BEGIN
LOCAL date_value, time_value;

//how comment (not that useful): update epoch adding the amount of seconds in an hour multiplied by the time zone difference.
//why comment: we need to align the epoch value to the defined timezone.
epoch:=epoch+sec_in_hour*zone;

date_value:=DATEADD(unix_epoch_start_time, IP(epoch/sec_in_day));
time_value:=(epoch MOD sec_in_day)/sec_in_hour;
RETURN({date_value, →HMS(time_value)}); 
END;

It may sound harsh, but it is not my intention. For me it is a pity to see shared code that seems minified and obfuscated unintentionally that then likely loses the chance to be picked and expanded by other members of the community.

Edit: of course, I assume you are typing your programs from a computer with a real keyboard. If you type them on the prime or on a touchscreen, I understand completely the short variables and the limited comments.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
epoch Prime - salvomic - 01-05-2018, 05:00 PM
RE: epoch Prime - pier4r - 01-05-2018, 06:03 PM
RE: epoch Prime - Dieter - 01-05-2018, 07:30 PM
RE: epoch Prime - salvomic - 01-05-2018, 07:42 PM
RE: epoch Prime - Dieter - 01-05-2018, 07:51 PM
RE: epoch Prime - salvomic - 01-05-2018, 08:07 PM
RE: epoch Prime - Dieter - 01-05-2018, 08:47 PM
RE: epoch Prime - salvomic - 01-05-2018, 09:10 PM
RE: epoch Prime - Dieter - 01-05-2018, 09:27 PM
RE: epoch Prime - salvomic - 01-05-2018, 09:36 PM
RE: epoch Prime - Dieter - 01-05-2018, 10:07 PM
RE: epoch Prime - salvomic - 01-05-2018, 10:16 PM
RE: epoch Prime - Dieter - 01-05-2018, 10:48 PM
RE: epoch Prime - pier4r - 01-05-2018, 09:40 PM
RE: epoch Prime - salvomic - 01-05-2018, 09:44 PM
RE: epoch Prime - Dieter - 01-05-2018, 09:56 PM
RE: epoch Prime - salvomic - 01-05-2018, 06:17 PM
RE: epoch Prime - salvomic - 01-05-2018, 11:26 PM
RE: epoch Prime - Dieter - 01-06-2018, 08:53 AM
RE: epoch Prime - salvomic - 01-06-2018, 09:28 AM
RE: epoch Prime - Dieter - 01-06-2018, 09:41 AM
RE: epoch Prime - Didier Lachieze - 01-06-2018, 09:50 AM
RE: epoch Prime - StephenG1CMZ - 01-06-2018, 09:40 AM
RE: epoch Prime - pier4r - 01-06-2018, 10:46 AM
RE: epoch Prime - Dieter - 01-06-2018, 12:42 PM
RE: epoch Prime - salvomic - 01-06-2018, 01:07 PM
RE: epoch Prime - salvomic - 01-06-2018, 02:45 PM
RE: epoch Prime - Dieter - 01-06-2018, 06:26 PM
RE: epoch Prime - StephenG1CMZ - 01-06-2018, 08:26 PM
RE: epoch Prime - Dieter - 01-06-2018, 08:37 PM
RE: epoch Prime - pier4r - 01-06-2018, 09:59 PM
RE: epoch Prime - salvomic - 01-06-2018, 10:07 PM
RE: epoch Prime - pier4r - 01-06-2018, 10:55 PM
RE: epoch Prime - pier4r - 01-06-2018 03:28 PM
RE: epoch Prime - salvomic - 01-06-2018, 03:45 PM
RE: epoch Prime - salvomic - 01-06-2018, 04:10 PM
RE: epoch Prime - StephenG1CMZ - 01-06-2018, 06:54 PM
RE: epoch Prime - salvomic - 01-06-2018, 07:58 PM
RE: epoch Prime - salvomic - 01-06-2018, 08:45 PM
RE: epoch Prime - Dieter - 01-06-2018, 08:59 PM
RE: epoch Prime - salvomic - 01-06-2018, 09:01 PM
RE: epoch Prime - Dieter - 01-06-2018, 11:07 PM
RE: epoch Prime - StephenG1CMZ - 01-06-2018, 11:24 PM
RE: epoch Prime - salvomic - 01-07-2018, 09:26 AM
RE: epoch Prime - Dieter - 01-07-2018, 06:22 PM
RE: epoch Prime - salvomic - 01-07-2018, 06:28 PM



User(s) browsing this thread: 1 Guest(s)