Forums

New names for .NET types?

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

New names for .NET types?

Postby Dr_Asik » Sun Nov 28, 2010 9:28 pm

From what I can see, Cobra seems to "rename" all .NET methods to start in lowercase, i.e. Console.WriteLine because Console.writeLine etc. Does that apply to any .NET assembly, for example if I created a C# type with PascalCase methods, do I have to call them as camelCase in Cobra?

Also a quick question about print. In Python 2, adding a comma after a print statement removed the newline. In Cobra, adding a comma is legal, but it doesn't seem to do anything. What am I missing here?
Dr_Asik
 
Posts: 7

Re: New names for .NET types?

Postby Charles » Sun Nov 28, 2010 9:57 pm

Only methods and properties start lower case. Type names (which include classes, interfaces, structs and delegates) remain uppercase.

Typically if you get the case incorrect, the Cobra compiler will directly tell you the correct case right in the error message.

You can also experiment with "cobra -correct-source ..." which will autocorrect some of these for you by writing back to your source code. If you can configure your editor to automatically reload modified files, this can save you some time. But it's also the feature everyone is afraid of. :-D

Cobra uses the keyword "stop" as in:
print 'Prompt:' stop

Unlike with a comma, there is no additional space printed. There is additional information at the Print Statement wiki page.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: New names for .NET types?

Postby Dr_Asik » Sun Nov 28, 2010 10:53 pm

Thanks again. I have another question. Here's my code:

class A
def blah
print "A!"

class B
def blah
print "B!"

class C
def blah
print "C!"


class Program
def main
myList = [A, B, C]
for i, type in myList.numbered
# This works:
type = myList[i]
type().blah
# This fails with 6 errors about brackets and parentheses
myList[i]().blah

So my question is, why does the last line fail? I figured the expression "myList[i]" evaluates to a type, so I should be allowed to add a pair of parentheses after just like I can with the variable "type" in the previous line.

Also, in that example, is blah() resolved statically or dynamically? In C# I would have had to say type is a dynamic but I'm not sure how Cobra does it.
Dr_Asik
 
Posts: 7

Re: New names for .NET types?

Postby Charles » Mon Nov 29, 2010 12:40 am

When you have a reference to a System.Type, as you do in your example, you can instantiate it with parens, as you have done. Cobra considers the type to be "dynamic" since there is no other reasonable choice (other than System.Object, but that's not as useful).

If you know more about the type of what you're instantiating, you can use a type cast like:
obj = type() to Shape


But you don't have to do that. Cobra supports both dynamic and static typing.

The last line in your example has triggered a bug in the code generation for which I'll add a ticket. The workaround is reasonable--break up the expression like you did above.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 11 guests