Recent

Author Topic: About identifier's case-sensitivity  (Read 3651 times)

Zoran

  • Hero Member
  • *****
  • Posts: 1829
    • http://wiki.lazarus.freepascal.org/User:Zoran
About identifier's case-sensitivity
« on: April 29, 2018, 05:59:54 pm »
Some languages, like Pascal, ignore case in identifiers. Other languages, like C-like languages, do not.

Some people prefer the first way, others the other. However, I have always wandered why no language takes the third way, the most strict, which I believe would be the cleanest, that is:
1. The identifier must be used with same case as declared. (as in C)
2. Declaring the identifier which case-insesitively matches another already declared is forbidden. (as in Pascal)

For example:

1.
Code: Pascal  [Select][+][-]
  1. var
  2.   AVariable: Integer;
  3. begin
  4.   AVaRiaBLe := 3; // compiler error, like in C
  5. end;
  6.  

However:
2.
Code: Pascal  [Select][+][-]
  1. var
  2.   AVariable: Integer;
  3.   AVaRiaBLe: String; // compiler error, like in Pascal
  4. ...
  5.  

Have you thought about this?
Isn't this the most error-preventing by its nature?

Of course, changing the rules of the language after decades is out of question. I'm just starting a discussion, because this third way just seems the cleanest and I'm surprised that the language creators just chose between case-sensitivity and case-insensitivity, and none used this mix.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: About identifier's case-sensitivity
« Reply #1 on: April 29, 2018, 06:11:26 pm »
Have you thought about this?

It has been brought up in groups about C and Modula2 languages, which are case insensitive. They often already have warnings for such cases. (but since it is legal per language spec, it IS allowed).

For Pascal it is irrelevant, since Pascal ignores case.

Quote
Isn't this the most error-preventing by its nature?

In case insensitive languages such errors can't happen. You can of course redeclare anything in a different scope, but that is not related to casing.
« Last Edit: May 02, 2018, 03:26:51 pm by marcov »

Zoran

  • Hero Member
  • *****
  • Posts: 1829
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: About identifier's case-sensitivity
« Reply #2 on: April 29, 2018, 06:45:49 pm »
It has been brought up groups about  C and Modula2 languages, which are case insensitive. They often already have warnings for such cases. (but since it is legal per language spec, it IS allowed).

Warnings? In Java, not only that no warnings are issued, but naming object the same as class, only with lower case, is actually very usual. I think that is their horrible convention:
Code: Java  [Select][+][-]
  1. // In Java code, this is very usual:
  2. Point point = new Point(2, 3);
  3.  

Have you thought about this?

For Pascal it is irrelevant, since Pascal ignores case.

Hm... yes, it's irrelevant now for Pascal, since it ignores case. It is irrelevant now for C, as it does not.
It is irrelevant for Pascal, for C, for Java,... because these languages took their ways long time ago.
I am just questioning why they took one way or the other, while I think the mix, which none of these took would be the cleanest.


Quote
Isn't this the most error-preventing by its nature?

In case insensitive languages such errors can't happen. You can of course redeclare anything in a different scope, but that is not related to casing.


In case-insensitive language you are allowed to do this:
Code: Pascal  [Select][+][-]
  1. var
  2.   AVariable: Integer;
  3. begin
  4.   aVaRiaBLe := 3;
  5. end;
  6.  

Not very nice. If it were forbidden, the code readability would be better.
So, it seems a bit strange that no language took this third way.

You can of course redeclare anything in a different scope, but that is not related to casing.

Of course I am talking about same scope.
« Last Edit: April 29, 2018, 06:49:48 pm by Zoran »

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: About identifier's case-sensitivity
« Reply #3 on: April 29, 2018, 08:46:07 pm »
I think that's because not all rules are compiler rules.

For example, I can create a class without starting it with T, like in Java "Point". And I can create a class in java starting it with T, and it compiles the same "TPoint".

I can create a lowercase class in java "point", a method starting with uppercase "Move". Like not following the 'rules'.

What I want to say, that all not need to be compiler rules. There are style guidelines for each language, that you can use to prevent the problems you say.

I think is easier and faster to check for one or the other, instead of checking by two rules at the same time.

Write a guideline for "cross language writing", and try to follow it you first.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: About identifier's case-sensitivity
« Reply #4 on: April 29, 2018, 08:54:38 pm »
And in addition to Lainz:

rules should be about correctness, not about visual appeal. Formatting wizards in the IDE are for appeal.

 

TinyPortal © 2005-2018