Page 1 of 1

A few questions from a newcomer

PostPosted: Sat Jul 18, 2015 6:17 pm
by AlexD
Hi all,

I stumbled on Cobra recently while looking for alternatives to Python that ran faster and didn't make me write "self." I was hoping to run a few questions by the community.

1. Is it possible to feed C# files directly into the Cobra compiler and use the classes defined therein? Or do I need to compile the C# first and @ref the classes?

2. Given that there are no free functions, what's the reason for accessing methods with the dot operator? If the call didn't look like some_object.method(...), you'd know it was a self/this call, so it wouldn't be ambiguous, right? Or am I missing something?

3. In this post, Charles explains his reasoning behind requiring a "base.init" call in every constructor:

I presume you mean letting the developer skip calling "base.init" or ".init" at the beginning of an initializer/constructor. Note that I gave two examples: "base.init" and ".init". I find that in C# and Java, developers don't seem to appreciate that there is an invisible call there whether they want one or not. The requirement for the explicit call is to make the developer decide what should really be done. When you have multiple initializers, say 4 of them, the correct answer is usually to chain the initializers, but in languages like C# and Java, developers almost always get this wrong and end up with 4 base/super calls instead of 1.


I'm used to C++, where the compiler will in fact insert a call to a no-arg base constructor if that's appropriate. I'm not sure I understand how someone could end up with multiple calls to a base constructor -- can anyone give me an example where this would be a problem?

Re: A few questions from a newcomer

PostPosted: Thu Jul 23, 2015 4:06 am
by hopscc
1. Is it possible to feed C# files directly into the Cobra compiler and use the classes defined therein?

yes.
You can mix .cobra and .cs files, .cobra files will be converted to cs and csharp compiled, .cs files will just be compiled, the bundle
combined into a single assembly.

2.what's the reason for accessing methods with the dot operator

(Visual/cognitive) consistency with instance variable access...
(or It looks nicer).


3. Explicit calls to constructors

My understanding of his rationale is that there is the possibility of an automatic wrong call to a (no-arg) base constructor when the correct setup should be to a constructor in the current class (or a multi-arg base constructor - case of multiple constructor methods, current and/or base). If all the calls are explicit its incumbent and forced on the writer to always explicitly call (the right) one.....