Forums

New to all of this

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

New to all of this

Postby renegadezero » Sat Mar 09, 2013 4:26 am

Hello there. I'm kinda new to the programming world, i've tried many different languages, and well, none seemed to flow. I was looking at some of the source code in Cobra and was overjoyed. no semicolon, brackets and what not.

I was looking at the how to and sample pages, and realized these contain things way more advanced than i am at this time. However i can understand this code somewhat but am a bit confused on something and would like to clear it up


"class Hello

def main
print 'Hello, world.'
"
ok so my basic question? here are why is hello given a class, is this necessary or simply good programming habit.
then def main. I'm guessing that this is like in batch scripting where u can basically name bits of code and use it later on but not 100% sure.

also is It _VarName and what is it that start .ThisName

As i hope i will always remember to say thanks in advance, and i hope i don't take anytime away from people really doing something
renegadezero
 
Posts: 2

Re: New to all of this

Postby nerdzero » Sat Mar 09, 2013 11:07 pm

Hello from one zero to another :)

I believe it was the Java language that started the trend of everything being an object and every function being contained within a class, including the main function. Not all languages work this way and it's not necessarily a good or bad thing, but it does keep things consistent.

renegadezero wrote:also is It _VarName and what is it that start .ThisName

I'm not sure I understand what you mean here. If you are asking what the significance of the _underscore and .dot characters are, then these are shorthand for referring to the instance variables and methods of a class. Having a leading underscore is a naming convention in some languages to indicate that this is not a public variable. In Cobra, it's more than a convention and is shorthand for making a field (instance variable) or method (class function) "protected". Two underscores make it "private". The dot character is also shorthand so you don't need to qualify the variable access like "this.variableName" or "self.variableName" like you do in some other languages.

You should google around for things like "object oriented programming", "inheritance", and "access modifiers" to learn more about these topics.
nerdzero
 
Posts: 286
Location: Chicago, IL

Re: New to all of this

Postby renegadezero » Sun Mar 10, 2013 1:02 am

Thanks that was what i was asking about the underscore and period stuff. So everything has to be within a class, consistency is good i think i will enjoy this quite a bit. thank you for the explanation. time to start practicing
renegadezero
 
Posts: 2


Return to Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron