QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: FellippeHeitor on November 30, 2020, 12:41:20 am
-
@STxAxTIC, @SpriggsySpriggs, @Cobalt and I share our coding styles and discuss how much it matters to make your code readable - and not just compilable.
-
Cool%, AnotherInteresting QB64_REPORT epi.sode.
I enjoyed listening to this over breakfast this morning.
Thanks.
- Dav
-
Cool%, AnotherInteresting QB64_REPORT epi.sode.
I enjoyed listening to this over breakfast this morning.
Thanks.
- Dav
LOL, love the variables!
Glad you enjoyed it! You're invited to join us next time too, man. I know you're familiar with microphones.
-
They talked about something interesting.
It has never turned my mind yet to be different to evaluate. I do it for myself, it’s really more transparent to me. Everything is on one screen, and if you believe it or not, I know exactly what it means when I look at it like this: “nex = ABS (sx = 0 OR sx = maze_x - 1) * -1 * SGN (sx)” I could have described this more in line with IFs as well, but why would it have been better? The mistake is that if I had to change something later, it would be a problem for me to understand.
But I respect your opinions!
I tried to find an explanation for this phenomenon. I never expected this to be a topic of debate. Maybe the language. I read somewhere that not someone will be able to write a good program because of how well they understand math, but because of how good their language is. I didn't deal with a foreign language, I know a little English, but I write this letter orally and then translate it with google translate.
Excessive compression may come from the Hungarian language, where up to 50 meanings can be created with 1 basic word and rag, sign, suffix, suffix. for example, “megszentségteleníthetetlenségeskedéseitekért”. Understanding this can be described in English in several sentences, full of the term “IF”.
Adding a rag, sign, suffix is universal to any word. I'm sorry, I was just trying to make some kind of excuse, an explanation. Maybe I'm wrong, I'm sorry.
I wrote a short little program that replaces ":" with "enter" in an ascii file, and will I be nicer? :)
-
You totally left out the discussion on coding in all caps, no remarks, no indentation, and no spacing between lines! You guys would have loved me, even more, back in the 1990's.
PETE
-
@MasterGy — The important thing is to code in a style which is decipherable for the user base of that code. It’s why many companies have such long, drawn out rulesets for how to properly code a program. As long as you’re coding for yourself, code in the style that makes the most sense to you. If you’re coding a library, or such, for other people to be able to use, or modify, in the future, then you need to adjust your style to be suitable for public consumption.
Someday, I’ll share some of my personal code with you guys. My personal style is a lot like Pete’s — short, compact, and which uses the most amount of real estate on the screen, to reduce scrolling and line count as much as possible. Yet, if I code something to share on the forums, I take time to try to unwind and expand those lines to make them as easily readable as possible.
_PRINTSTRING (bx + (bw - tw) / 2, by + fh * i), t$
For the above, I’ll go into search and replace all in the IDE and swap bx to BoxLeft, bw to BoxWidth, tw to TextWidth, by to BoxTop, fh to FontHeight, and t$ to temp$.
Now all my abbreviated variables, which made perfect sense to me, now hold some self-documenting meaning for others. (The above would basically center multi-line text into a boxed area of the screen for me, while inside a loop.)
Of course, sometimes even the best attempts at making code understandable fails. The other day, on Discord, I was questioned about some code I’d shared which was basically:
IF x THEN IF y THEN do_something ELSE do_other_stuff
To me, this makes perfect sense, and I didn’t think it needed unwinding further. Others had never seen an IF inside an IF and didn’t know how to decipher that. They didn’t know where that ELSE might relate to: the IF x, or the IF y. Breaking it down to the following allowed them to instantly comprehend it:
IF x THEN
IF y THEN do_something ELSE do_other_stuff
END IF
At the end of the day, coding style is all about attempting to code in a manner to make it easy for the user-base to read, understand, and work with the code in the future.
-
Thank you, SMcNeill, for making it clear to me the importance of "coding style"! to understand, apply, see through others as well. Since I’m here on the board too, it’s like we’re all sitting by the campfire. Let everyone understand that when we go hunting, we can be more efficient!
-
Yeah, you guys go hunt. Me, I'm ordering pizza.
I remember a challenge at the QBasic forum to submit the most obfuscated code. I misread the post, and thought it meant the most efficient code. Still, I ended up winning the contest, anyway, go figure...
I can't say I could go back to my old ways, described in my last post, and still understand my programs. So my coding style has changed to accommodate my advancing age. What I play around with these days is variable naming. In the old days, I limited variable names to one or two characters, to save memory in QB45. I still have an easier time reading a program with short variables, than long descriptive names, but at some point, too many short named variables also gets hard to keep track of what's happening in the code.
I have wondered about what "standards" professional programmers, who work in groups, are held to. If one person is working on a project, all that matters is it works when it's compiled; but if many are working together, it may slow down the project if they all have to take the time to figure out another coder's style. For instance, when Mac asked me and two others to join him in his Danish chess program at the QBasic Forum, we put together a simple standard that worked for that project. It didn't require looking into any other contributors style. Simply put, each member of the group was required to certify that their module (contribution) worked. Mac's job was to join these three modules together, which would not require modification of any one contributor's code. If a problem was encountered in joining the modules, the coder of that module was asked to modify his code and thereby adapt it to the conditions needed for the joining process to be successful.
Pete
-
@MasterGy I hope you didn't get offended for being mentioned, but your program was chosen as an example exactly for being so amazing but also so hard to read at the same time, and the fact you voluntarily decided to make it more readable was really kind. Glad to have you in the community! Now go fetch us some marshmallows.
🌳🏕
-
You totally left out the discussion on coding in all caps, no remarks, no indentation, and no spacing between lines! You guys would have loved me, even more, back in the 1990's.
PETE
Shivers down my spine.
-
I'm not offended! In fact, I felt honored to be mentioned. A handful of it is a team here, few already practice this language developed from dos. You are the ones who evaluate when something is made, so I owe you a debt of gratitude for being here. As for the campfire, I really understand the point!
For example. „Prog.hu” .Paid, educated application development group in Hungary. They produce value-creating things, and when I present, they don’t understand what I’m showing. They don't see the value, the marketability. Because there isn't. You are the ones who (for me) can really appreciate it.
-
Cool report.
it's fine to ear different way to think how structuring the code, how to choose the name of variables, how .BM and .BI files can be thought and used.
Well, I'll find interesting experiences and opinions about group programming. The opinions left here above from Pete and Steve are interesting points of view.
-
It's screaming snake case because it's snake case but in CAPS, and people writing in CAPS are SHOUTING...or SCREAMING.
I'll leave you with a few quotes:
The best programs are written so that computing machines can perform them quickly and so that human beings can understand them clearly. A programmer is ideally an essayist who works with traditional aesthetic and literary forms as well as mathematical concepts, to communicate the way that an algorithm works and to convince a reader that the results will be correct.
Don't put multiple statements on a single line unless you have something to hide.
Programs are meant to be read by humans and only incidentally for computers to execute.
Real programmers can write assembly code in any language.
Spaces in variable names won't be a thing as long as we have "our universal preoccupation with BNF grammars and their various offspring". (Pratt, 1973).
-
You're invited to join us next time too, man. I know you're familiar with microphones.
Hey, Thanks for the invitation. I'll have to think about that. Maybe another one down the road instead?
Feels nice to be asked.
- Dav
-
Fascinating discussion. I'll try to take some lessons from that. Since my coding kung fu style is mostly 'poo flinger', it might help.
-
Combining comments made here in Discussion Program and an old, old comment I read about using all CAP's for CONSTants, I am trying a new system of Capital letter start of all Globals or SHARED variables that I always have declared at start after CONSTs and TYPEs. That and I took to heart the comment of overuse? of just a couple of letters for variable names. Now I will try to at least be more descriptive with Global SHARED constants and variables but in little SUBs and FUNCTIONs or even that Main, I don't see it as necessary. It should be obvious in the context.
A little defensive: surely you guys know x, y, z for position coordinates w, h for width and height, maybe too r, c are short for row and column, mx, my, mb are mouse updates...
Now I can clearly see what variables are coming from 'nowhere' (the beginning of the program declared Globals) and know what they are from CAPs and better description.
Word Search Puzzle Builder is my first program with that style purposely imposed: https://www.qb64.org/forum/index.php?topic=3311.0
So if it reads better than my usual, it's from your influence here :)
Yes I agree that code should read as well as program functions, they could likely contribute to each other specially psychically for human creators.
So Zack is Spriggsy, Dave is Cobalt and Bill looks a little like my room mate from college the semester I had my best GPA and who was a physics major also. I pictured Bill with Black hair, about every Bill I ever knew had Black hair, funny how wrong our imagination can be.
-
...Dave is Cobalt...
This is why they don't let me participate in these reports. If Cobalt logged on, all he'd get from me is "Dave's not here, man."
Pete
-
I definitely think we should all arrange to meet online any day. Several mysterious faces would show up and it'd be awesome! Let's do it before Christmas comes!
-
Dave's not here, man.
-
@bplus Looking forward to the final version!
-
Dave's not here, man.
-
Dave's not here, man.
Ahhhhhhhh
-
+ ahhh that's where that started. :) I could here the voice but not place the face or context.
Is Dave going to get a new nickname? ;-))
-
Dave's not here, man.
-
Fellippe wrote:
I definitely think we should all arrange to meet online any day. Several mysterious faces would show up and it'd be awesome! Let's do it before Christmas comes!
You know, I'd love to talk to you. But I'm not capable of that. Without the captions in your video, I'd vaguely know what we're talking about. I don't speak spoken English at all. I am still a child from communism, I learned Russian .... and then German. Finally, I try to communicate in English. Life is just as special, it's never the way one imagines it. Frankly, my inability to speak English annoys me terribly.
-
Let me help...
Step 1) Buy a SCREEN 0 tee-shirt from QB64.org.
Step 2) Log on to the report channel.
Step 3) Point to "SCREEN 0" lettering on your tee-shirt throughout the entire discussion.
That's just good YouTube.
SCREEN 0, it's the only English anyone should ever need.
Pete
-
This is why they don't let me participate in these reports. If Cobalt logged on, all he'd get from me is "Dave's not here, man."
Pete
Dont you mean,
"I'm sorry Dave, I'm afraid I can't do that."
-
Dave's not here, man.
-
Do I still come off as Monotonous?
I may just not be a public speaker, I guess.
Maybe next time I'll try to use a slight Scottish\Irish accent, makes my daughters laugh and giggle when I read to them that way.
Just like Pete when he thinks about Clippy!
-
Hi Cobalt,
Don't worry, easier said than done I know. If you really want to be a public speaker or just be better there are things you can do.
#1 that comes to my mind is having talking points you eager to share.
-
I like these where it's familiar forum members! Needs me, bplus, and Steve up there!
-
Come everyone!
-
@bplus Looking forward to the final version!
If we are talking about Building Word Search Puzzles from Word List files, I've got to say, "I thought I was done already."
But with Richard Frost feedback and my announcing my new Coding Style "experiment" as a result of your program maybe you guys can use the code as an practical which means concrete example to use as examples for good or bad in the interest of better code writing for everyone, I dont think I'd mind if we stick to the intention of better code writing.
Part of my style is going back and modifying old code so having something I wrote 2 years ago and running into a bug, it is important to me how fast you can get up to speed with something you wrote in past so you can fix and make better.
When is final version? When I am dead and buried or when someone else picks up some crumbs and makes better?
-
@bplus
cool!
Part of my style is going back and modifying old code so having something I wrote 2 years ago and running into a bug, it is important to me how fast you can get up to speed with something you wrote in past so you can fix and make better.
this kind of mental attitude is the same of Francesco Petrarca (https://en.wikipedia.org/wiki/Petrarch (https://en.wikipedia.org/wiki/Petrarch)) who wrote and wrote again its masterpiece il Canzoniere https://en.wikipedia.org/wiki/Il_Canzoniere (https://en.wikipedia.org/wiki/Il_Canzoniere). The goal of writing again was to reach a superior level of the work.
-
@bplus
cool!this kind of mental attitude is the same of Francesco Petrarca (https://en.wikipedia.org/wiki/Petrarch (https://en.wikipedia.org/wiki/Petrarch)) who wrote and wrote again its masterpiece il Canzoniere https://en.wikipedia.org/wiki/Il_Canzoniere (https://en.wikipedia.org/wiki/Il_Canzoniere). The goal of writing again was to reach a superior level of the work.
Yeah very popular around the world, Japanese have a word for it, Tony Robbins has CANI (if I recall correctly) Constant And Never-ending Improvement, something like that. Tons of acronym's in Self Help and Positive Psychology great attitude or spirit, up there with GRIT.
-
I tried thinking positive once, but my brain became too inundated with a whole bunch of homeless electrons. Shocking.
Pete
-
I tried thinking positive once, but my brain became too inundated with a whole bunch of homeless electrons. Shocking.
Pete
LOL Yeah that must be how it works :) that's when the lights go on and you say to yourself. "Only SCREEN 0, what was I thinking!"