Recent

Author Topic: Do underscores have a special meaning in component names?  (Read 965 times)

vfclists

  • Hero Member
  • *****
  • Posts: 1013
    • HowTos Considered Harmful?
Do underscores have a special meaning in component names?
« on: February 22, 2024, 09:39:59 pm »
I understand that underscores are permissible in component names and variable names, but is there some kind of convention concerning their use, whether as the first character, last character or somewhere in between?

I assume that they have no special meaning in the middle, unless they have some use cases in specific areas agreed by convention.. I have never used them in the past, but I now use them to separate the parts of constructed names (thanks to 127 character identifier length).

Having them at the start and the end is what I'd like to know now, and whether both Lazarus and Delphi developers attach some significance to their placement.

Lazarus 3.0/FPC 3.2.2

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2042
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Do underscores have a special meaning in component names?
« Reply #1 on: February 22, 2024, 10:39:32 pm »
From my Delphi past I did used underscore when I replaced some original content. But I guess that each developer has there its own strategy. As long you document it all is good.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Thaddy

  • Hero Member
  • *****
  • Posts: 14348
  • Sensorship about opinions does not belong here.
Re: Do underscores have a special meaning in component names?
« Reply #2 on: February 23, 2024, 06:58:40 am »
I assume that they have no special meaning in the middle, unless they have some use cases in specific areas agreed by convention.. I have never used them in the past, but I now use them to separate the parts of constructed names (thanks to 127 character identifier length).
You can use it anyway you like.
I know some shops, more than one, however, that have a provision for underscores at the start of a  procedure or function to indicate code that even if declared in the interface section the code should be treated as local to the unit. This can be the case with circular references between units and is purely notational.
But otherwise I am not aware of any conventions. If you come across such code as I described it is likely that may be the intention of the coder.
The old Frank Borland used it that way, so it may have trickled through to others.
« Last Edit: February 23, 2024, 07:01:49 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Thaddy

  • Hero Member
  • *****
  • Posts: 14348
  • Sensorship about opinions does not belong here.
Re: Do underscores have a special meaning in component names?
« Reply #3 on: February 23, 2024, 07:57:57 am »
Basically for readability
??? You mean code obfuscation by underscores?
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

domasz

  • Sr. Member
  • ****
  • Posts: 433
Re: Do underscores have a special meaning in component names?
« Reply #4 on: February 23, 2024, 10:39:45 am »
Sometimes underscores are great in component names.

For example I can put TEdits on a form and name them NumberEdit_1_1, NumberEdit_2_1, NumberEdit_1_2 then assign 1 OnClick procedure to all of them and use component name to easily get X,Y position in some array.

Thaddy

  • Hero Member
  • *****
  • Posts: 14348
  • Sensorship about opinions does not belong here.
Re: Do underscores have a special meaning in component names?
« Reply #5 on: February 23, 2024, 11:17:19 am »
I was referring to
Code: Pascal  [Select][+][-]
  1. _ItIsPublicButIgnoreThatBecauseItIsReallyLocal
If that makes sense. :-[ :-X O:-)
« Last Edit: February 23, 2024, 11:20:00 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

VisualLab

  • Sr. Member
  • ****
  • Posts: 298
Re: Do underscores have a special meaning in component names?
« Reply #6 on: February 23, 2024, 03:44:53 pm »
I understand that underscores are permissible in component names and variable names, but is there some kind of convention concerning their use, whether as the first character, last character or somewhere in between?

I assume that they have no special meaning in the middle, unless they have some use cases in specific areas agreed by convention.. I have never used them in the past, but I now use them to separate the parts of constructed names (thanks to 127 character identifier length).

Having them at the start and the end is what I'd like to know now, and whether both Lazarus and Delphi developers attach some significance to their placement.

This is a very nasty habit, heavily overused in C and Python. It worsens the readability of the code (not to mention its unnecessary length). This type of "practice" is a form of sloppiness. It is better to "level up, not down."

 

TinyPortal © 2005-2018