Recent

Author Topic: Do you number your begin/end blocks?  (Read 3114 times)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12536
  • FPC developer.
Re: Do you number your begin/end blocks?
« Reply #15 on: September 02, 2025, 11:21:47 am »
I don't number them, even if I thought it would be useful, when coming back to code you would have to check if the numbering is still correct.

I use the other ways proposed in this thread; Indentation, early exits and in general not making procedures too long.

creaothceann

  • Full Member
  • ***
  • Posts: 205
Re: Do you number your begin/end blocks?
« Reply #16 on: September 02, 2025, 12:19:37 pm »
Speaking of indentation, why not 8-char tabs?

Code: Pascal  [Select][+][-]
  1. if this then begin
  2.         if otherthing then begin
  3.                 if anotherthing then begin
  4.                         //...
  5.                 end;
  6.         end else begin
  7.                 //...
  8.         end;
  9. end;
Quote from: Thaddy
And don't start an argument, I am right.
Quote from: Thaddy
You have a thorough misunderstanding of what I wrote. Can you provide an example this time? I doubt it. (because you never do out of incompentence)

Thaddy

  • Hero Member
  • *****
  • Posts: 18363
  • Here stood a man who saw the Elbe and jumped it.
Re: Do you number your begin/end blocks?
« Reply #17 on: September 02, 2025, 01:15:02 pm »
NEVER use real tabs (#9) for whitespace in sourcecode. It kills the code in other editors all to easily.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

creaothceann

  • Full Member
  • ***
  • Posts: 205
Re: Do you number your begin/end blocks?
« Reply #18 on: September 02, 2025, 02:06:24 pm »
How so?
Quote from: Thaddy
And don't start an argument, I am right.
Quote from: Thaddy
You have a thorough misunderstanding of what I wrote. Can you provide an example this time? I doubt it. (because you never do out of incompentence)

Thaddy

  • Hero Member
  • *****
  • Posts: 18363
  • Here stood a man who saw the Elbe and jumped it.
Re: Do you number your begin/end blocks?
« Reply #19 on: September 02, 2025, 02:27:02 pm »
Try to work with different editors: gets expanded in all kind of different formatting.
Usually - if the editor has such an option - replace #9 with spaces. You can still use tab, but the formatting stays.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

TBMan

  • Sr. Member
  • ****
  • Posts: 282
Re: Do you number your begin/end blocks?
« Reply #20 on: September 02, 2025, 04:46:16 pm »
Python wouldn't even compile if the indentation is not correct...

I was interested in learning Python. I downloaded some things to get started and when I ran into that I was put off by it.
It didn't make any sense to me. Different operators and different syntax, fine, but indentation rules?
Maybe I will try it someday regardless.
I love programming.

Some things I've done using PTCgraph:

NFL Retro Football (almost finished):
https://www.youtube.com/watch?v=78mTtsd7ppk


Solitaire games:
https://www.youtube.com/watch?v=zmtxI7FdWuQ&list=PLa4BPpFl34iVhFwX1JZwVm3vE5ay_i3R2

440bx

  • Hero Member
  • *****
  • Posts: 5820
Re: Do you number your begin/end blocks?
« Reply #21 on: September 02, 2025, 04:59:56 pm »
Different operators and different syntax, fine, but indentation rules?
I know what you mean.

That said, formatting rules are nothing new.  FORTRAN, COBOL, RPG and other languages had some formatting rules the programmer had to adhere to in order to produce something that would compile.

Once a programmer gets used to a free-form programming language, formatting rules feel like an unnecessary straitjacket.  I find relying on indentation a rather hokey thing but, that's the python way.

FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 18363
  • Here stood a man who saw the Elbe and jumped it.
Re: Do you number your begin/end blocks?
« Reply #22 on: September 02, 2025, 05:14:06 pm »
In Python it is an essential part of the language. Indent wrong, not working. I like that a lot, maybe because I - almost always - follow an indentation rule of two spaces per block.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

suve

  • Newbie
  • Posts: 6
Re: Do you number your begin/end blocks?
« Reply #23 on: September 02, 2025, 05:43:53 pm »
Since Pascal is case-insensitive, I tend to use Begin-End for procedure/function blocks and begin-end for inner blocks.
Plus indentation, obviously. (ASCII TAB gang here.)

creaothceann

  • Full Member
  • ***
  • Posts: 205
Re: Do you number your begin/end blocks?
« Reply #24 on: September 02, 2025, 06:00:34 pm »
Try to work with different editors: gets expanded in all kind of different formatting.

Yeah, but that wouldn't be a problem for my code. I only use tabs before the first non-whitespace character; aligning comments etc. only via spaces.
Quote from: Thaddy
And don't start an argument, I am right.
Quote from: Thaddy
You have a thorough misunderstanding of what I wrote. Can you provide an example this time? I doubt it. (because you never do out of incompentence)

TBMan

  • Sr. Member
  • ****
  • Posts: 282
Re: Do you number your begin/end blocks?
« Reply #25 on: September 02, 2025, 11:07:19 pm »
In Python it is an essential part of the language. Indent wrong, not working. I like that a lot, maybe because I - almost always - follow an indentation rule of two spaces per block.

I bet once someone gets used to doing that it becomes second nature and the code is easier to read.
I love programming.

Some things I've done using PTCgraph:

NFL Retro Football (almost finished):
https://www.youtube.com/watch?v=78mTtsd7ppk


Solitaire games:
https://www.youtube.com/watch?v=zmtxI7FdWuQ&list=PLa4BPpFl34iVhFwX1JZwVm3vE5ay_i3R2

Kraig

  • New Member
  • *
  • Posts: 28
Re: Do you number your begin/end blocks?
« Reply #26 on: October 08, 2025, 02:13:10 pm »
I use indentation and if necessary comments for begin ends

Warfley

  • Hero Member
  • *****
  • Posts: 2021
Re: Do you number your begin/end blocks?
« Reply #27 on: October 08, 2025, 03:59:09 pm »
This gets me out of a lot of trouble.
The problem with this is that if you insert a single block you might need to rename a bunch of other blocks. If you just need to fix something in a hurry, you may overlook something and then your numbering is broken.

And if you rely on that numbering, broken numbering can be worse than no numbering.
This btw holds for any comments, not updated comments and documentation is a major source of bugs in large scale projects that involve multiple developers

dbannon

  • Hero Member
  • *****
  • Posts: 3568
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Do you number your begin/end blocks?
« Reply #28 on: October 09, 2025, 08:38:33 am »
I use code tools for that. I checked outline and gave the lines a light blue color. Now all I have to do is follow the line down at an if.

Wow, I did not know about that. !  While I usually rely on indentation, I sure am going to give outline a try !
Thank Hansvb
Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11824
  • Debugger - SynEdit - and more
    • wiki
Re: Do you number your begin/end blocks?
« Reply #29 on: October 09, 2025, 10:05:58 am »
If your blocks have begin/end, then "Find other end of code block" (from the search menu). Or assign it to a key.

And you can also have the editor highlight the end for the current (at cursor) begin (or vice versa) => options > editor > markup > word brackets.

The outline can also have different colors for different levels, making it easier to trace. Even include coloring the if then begin according to its level.

 

TinyPortal © 2005-2018