Curious if I am thinking about this right. - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: Curious if I am thinking about this right. (/showthread.php?tid=3395) Pages:
1
2
|
Curious if I am thinking about this right. - protocog - 01-19-2025 I am trying to get good at writing simple code that is easy to read. I took up that assignment of writing a Inches to millimeters conversion calculator in Lesson 2 of the tutorial. All I am asking is is there any way to improve my code? I added the option to convert to millimeters to inches. Code: (Select All)
Thanks for any feedback! RE: Curious if I am thinking about this right. - bplus - 01-19-2025 Looks good to me, commenting your variables is great habit for readability. Welcome! RE: Curious if I am thinking about this right. - bplus - 01-19-2025 A way for less lines employs the new _IIF keyword Plus some strategic rearrangement: Code: (Select All)
RE: Curious if I am thinking about this right. - protocog - 01-19-2025 (5 hours ago)bplus Wrote: A way for less lines employs the new _IIF keyword Plus some strategic rearrangement: Definitely much simpler. Thanks for taking the time to do that. RE: Curious if I am thinking about this right. - CharlieJV - 01-19-2025 (5 hours ago)protocog Wrote: ... I think the readability of your code is top-notch. Anyone might have tiny nit-picky things they might prefer, but then those would be things others might not prefer. For the giggles ... I have a cognitive disability made worse by Fuchs Dystrophy (blurry vision). So I'm on a really fussy extreme in regards to code format/organization to keep me from getting stuck in the mud or having sticks stuck in my wheels (i.e. avoid slowdowns trying to process what I'm looking at, and avoid playing "where's Waldo" games.) You probably don't want to write code this way because I imagine you are going to quickly annoy other people. Me, I'm at an age at which I don't really give a rat's caboose what anybody thinks (unless they want to pay some significant dinero, at which point I'm like: any way you prefer.) RE: Curious if I am thinking about this right. - bplus - 01-19-2025 Ha! even less work Code: (Select All)
RE: Curious if I am thinking about this right. - protocog - 01-19-2025 (5 hours ago)CharlieJV Wrote:I respect it. As long as the code works and to me I think works just as well. And I agree, some folks are insanely picky.(5 hours ago)protocog Wrote: ... (5 hours ago)bplus Wrote: Ha! even less workAbove and beyond thanks brotha. I have yet to use a _IIf function. RE: Curious if I am thinking about this right. - CharlieJV - 01-19-2025 (5 hours ago)bplus Wrote: Ha! even less workOh you speed demon, I was in the midst of doing something similar while you posted that. RE: Curious if I am thinking about this right. - bplus - 01-19-2025 Half again (I probably should have tested this) Code: (Select All)
Are the Input questions not explanatory comment enough for the variables? The beauty of Basic is that you don't have to Dim plain variables. EDIT: a comment added to explain where the 25.4 number is coming from RE: Curious if I am thinking about this right. - SMcNeill - 01-19-2025 Personally, I'd just do something like this in the simplest repeatable way possible: Code: (Select All)
For a quick and easy tool like this, why bother to choose an operator? Just give both results and save the work, with the process inside a loop to keep it going until you're finished with it. And that's not to say that the original code is wrong, or bad, in any sort of way. The important thing in coding is to end up with a *finished product that works and does the job desired*. It does that, and it does it nicely. There's nothing in the world wrong with it. It's just nice to sometimes see how other people would handle the same task, and compare methods so that we can optimize our own way of thinking and learn from them, or teach them a trick or two which they may not have thought of for themselves. *YOUR* way works just fine. *My* way works just fine. Neither is better. I just personally prefer to make my programs where they require the least possible amount of input and effort at run time. I don't to choose an op here, I just provide a simple number; and I don't need to restart to produce a second number. Run it, let it go until I hit <enter> or try and convert a value of 0, and then I can simply type in one value at a time and just glance at the screen as to what my desired converted number is. I'm lazy. I like to program in a manner that supports me being as lazy as possible. |