Better VBA 5 - Code Formatting

preview_player
Показать описание
A fundamental factor for the readability of source code is its formatting. I thought is to be too trivial to justify making a video about it. My daily experiences with code written by other developers, beginners and intermediates alike, indicate otherwise. So, here I show the difference in readability between poorly formatted code and well formatted code.

The web-page to the Better VBA series:
Рекомендации по теме
Комментарии
Автор

Readability is really important. I like that line continuation trick to move the Then inline with the If. This is changing the way I code now.

michaelkrailo
Автор

Stumbled upon your videos for this series. It’s already helping me understand how I can improve my code writing skills. Thank you for sharing your expertise. Subscribed!!

FlacoSalsero
Автор

It's very rare (or it is just me) to see the conditions splitting in IF statement, but this is the beauty of programming - there is no the only 1 solution to code! Cheers!

SimpleExcelVBA
Автор

It's great to have my practices validated by an expert like you 🙏

kamatchinmay
Автор

Indenting makes logic so much more clear! Thanks for making these videos, Phillip, they will help lots of folks write code that is more logical and therefore, easier to follow, including me.

on indenting ... especially when you can see a whole block on the screen, I think it is valuable to show, or at least point out (you did it too fast to see) to 1. select everything within the first and last block statements (like If... and End If) on whatever level you are working on and 2. press Tab to indent the selection.

I am one who keeps On Error indented one tab stop ... unless I change it within a procedure. Then I do sometimes put it at the root level -- but more often, I add comment lines to separate the section since I normally consider the root position within a procedure to be temporary, such as Debug.Print statements.

Line continuation is another great tip for making code easier to read (and what I have against auto-indenters since I like my tab stops the best ... but when I didn't write the code, they're great). Some like Adrian actually make a conscious choice to stop all statements at or before 80.

Very interesting putting Then at the beginning of a line. My solution for nested If conditions on lots of lines has been to indent the continuation lines of the condition one level past the block they run ... but maybe I will change to your method. I've not seen that way in VBA before, so something to consider.

C developers seem to like more on one line, which often have multiple statements too, but like you, I think it makes code easier to read to separate actions onto their own lines.

I watch your videos because I think you are a good teacher, clearly knowledgeable, and I could learn some teaching tips from you ... and, pleasantly, I am also learning cool things I didn't know, and you bring up good points about coding that I hadn't considered before -- nice bonus. Thanks for sharing.

LearnAccessByCrystal
Автор

This is exactly what I've been looking for. Thank you so much!

Jallandhara
Автор

Learned something new again ... thanks.

MD-xsfx
Автор

Hi Philippe ! You are Doing a very good job here ! I have a suggestion about the contain, I see that all the video is about readability, and the example of code is too long to understand what is going on the screen . Focus on issues that people having on the code.and How to go around. We are not a very taff programmers, so organising the code is not our last issue .

sissokom.prodev