Forums

Implicit main()?

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

Implicit main()?

Postby cathalgarvey » Thu Jan 09, 2014 6:41 pm

Hey all,

Thank you, Charles, for Cobra. I'm really getting into it as a tolerably fun-to-code compiled language, and I'm happy to have something lower level than Python but less aggravating than C<whatever>. :)

One thing that annoys me about C++/C#/Java though, which has carried by inheritance into Cobra it seems, is the requirement for a class and method to contain statements that should run at program launch. That is, after all the classes are made, the statements that actually use those classes and methods to do stuff are always wrapped in a class and method.

I won't ask why anyone thought this was a good idea to begin with, because to me it just looks like so much cruft. I'm sure they had their reasons. Instead, I'll just make a little code request.

As a proud Pythonista, I'd be happy to see a way to directly code without explicit classes, and have the compiler wrap those bottom-level statements in a class and method automatically. So if a code fragment contains function definitions and statements outside of a class, the functions are silently converted to methods of an anonymous wrapper class and the statements are placed into a main() method of that class.

I realise this isn't as dynamic as Python and so there would still be constraints on how to code in this way so that Cobra doesn't throw a fit. For example in Python one can write a function, use it several times, then overwrite it, or conditionally overwrite it, or wrap it: I'm not sure this sort of dynamicism is possible in Cobra, and so Cobra might throw a bug, but if that bug is thrown after rewriting the code into an implicit class/method, then it won't be obvious to the hapless coder where they made their mistake.

Still, it's food for thought; less cruft, more aesthetically pleasing code, but it's implicit conversion so purists can still code in
class Prog
cue main()
print "Feel better about myself"

if they so choose.
cathalgarvey
 
Posts: 4

Re: Implicit main()?

Postby kobi7 » Sun Jan 12, 2014 10:05 am

you say it's cruft, but I see it as more organized.
when statements are just spread around, it looks like a mess.
I think this decision is good, since it promotes among first timers cleaner more structured code, rather than do the quickest thing to make it run. (see php for an infamous example, okay maybe I'm too harsh here)
My point is consistency is good. when you get yourself into trouble, debugging, trying to realize what's wrong, it helps in a major though subtle way.
i think there is a rationale here, though maybe i'm just bikeshedding...
Falun Dafa is Good.
Truth, Compassion, Forbearance is Good.
kobi7
 
Posts: 82
Location: Israel


Return to Discussion

Who is online

Users browsing this forum: No registered users and 20 guests