C# vs Oxygene case sensitivity


(Bob Russell) #1

Having just spent some time figuring out conversions between C# and Oxygene, and at the risk of re-opening what is presumably an old question - as I understand it, C# is case sensitive, while Oxygene is case conserving. Given the common convention for C# code to use constructs that make a class name “the same as” the instance name, apart from case, doesn’t this cause a problem for Oxidizer? (Not to mention me, trying to figure out the code).

Just interested…


(marc hoffman) #2

Correct.

There’s two aspects to this, really.

For one, even in Oxygene, there are separate “lets not call them namespaces” spaces for identifiers, depending on context. a type can have the same name as a property or field, say, and depending on the location in source, that’s no problem, eg:

property Button: Button;

is perfectly fine (regardless of case, even). Of course this does not extend to having two items with the same name in the same scope (eg a property and a field), which is fine in C# if they differ in case, but not in Oxygene.

More importantly though, regarding your question: Oxidizer does not understand code, it performs mere syntax conversion of code that may, very well, be incorrect (e.g. refer to unknown types or variables). As long as the syntax is valid, Oxidizer can parse the code and translate it, but it gives no thought to whether the code (original or translation) is correct. As such, it’ll happily keep all your identifiers as they are, and not know of care if the end result is, in fact, ambiguous or wrong code.

Think of it as as this: I could write a paragraph of English text that talks about two people called Bob, and if I’m a bad writer, the text might be confusing as to which Bob I’m referring to where. If I ask someone to translate this text to, say, German, the translator can translate the text fine, but it’ll remain just as ambiguous.

It’s the same with Oxidizer. it knows to turn “foreach (var x in x) x” into “for each x in x do x”, but it has no idea what each of the x means in relation to the code or each other.


(Bob Russell) #3

Marc, Many thanks for this - it really clarifies how Oxidizer works. Coming from a Delphi background (not case sensitive - and not case conserving either, which always irritated me - I loved the VB code completion case correcting) where the main general convention is to prefix Types with a T, to distinguish them from instantiated versions, I still find the C# convention less easy to interpret - just my background.

More specifically though, if I have a C# snippet that defines a class and then instantiates it with a variable name that differs only in case, Oxidizer will convert the syntax, and conserve the case, but the resulting Oxygene code would not compile? Not complaining, but just for understanding…?


(marc hoffman) #4

That’s one of the cases that should be fine, var button: Button, as types live in a different scope. What will cause problems is stuff like

private string foo;
public string Foo { get { return foo; } }

as here both foos would live in the same scope.


(Bob Russell) #5

Understood. Thanks