|
journal
all | Rob is 20,354 days old today. |
Oct 2022 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Feb 2023 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
2022
jan feb mar apr
may jun jul aug
sep oct nov dec
2024
jan feb mar apr
may jun jul aug
sep oct nov dec
|< << more >> >| |
Entries this day: chatgpt-helped-me-write-some-simple-code chatgpt helped me write some simple code (written 10:22 Saturday 14 January 2023 JST) Chat GPT helped me out yesterday. I didn't want to be bothered to search how to do this, and embarrassingly I didn't know instantly how to do it with Here was my prompt: write php code to check if two numbers are within 10000 of each other In a trice, I got this back: This code uses the abs() function to calculate the absolute difference between $num1 and $num2. If this difference is less than or equal to 10000, the message "The numbers are within 10000 of each other" will be printed. Otherwise, the message "The numbers are not within 10000 of each other" will be printed. Wow. Well, that ain't bad, but it could be better: use a variable for the constant In this code, we have a variable $difference that holds the constant value of 10000. This value is then used in the comparison to check if the difference between $num1 and $num2 is less than or equal to $difference. This allows you to easily change the threshold for "within x of each other" by changing the value of the $difference variable. Then I tried to really push the limits with a horribly unclear and unpunctuated query: why wouldn't you call difference tolerance? Misunderstaning my meaning, it gave an otherwise reasonable response: "Difference tolerance" would be a more appropriate name for the variable that holds the constant value of 10000, as it represents the tolerance or range within which the numbers are considered to be close to each other. Naming variables in a way that reflects their purpose makes the code more readable and easier to understand. The term "difference tolerance" gives a clear indication of what the variable is used for, whereas the term "constant" does not. It could also be named "threshold" or "range", as it represents the range within which the two numbers are considered close to each other. I decided to go easy, using some punctuation: well, fix the name of the constant In this code, the variable $tolerance holds the constant value of 10000, which represents the range within which the two numbers are considered to be close to each other. The variable is appropriately named "tolerance" as it reflects the purpose of the variable. This makes the code more readable and easy to understand. Wow. Interesting enough to post it here. Screenshots: permalinkprev day next day |