Saturday, March 24, 2007

The 400

Forget about the 300... Cobra hit 400... test cases tonight. It looks like a nice, strong number when the test suite finishes:

400 Tests in 00:04:40.7474784.
Success.

I suppose there are really 401 since the compiler is written in Cobra and forms the last and most complex test case.
So Cobra 0.5 is coming up. It will feature:

  • A new trace statement to aid debugging (think "print statements on steroids").

  • Support for optional dynamic typing. Pick static or dynamic at your pleasure.

  • Better error checking and messages.

  • Better "cobra -test" behavior.

  • The usual round of refinements and bugfixes.


I'm in the home stretch for this release with more testing, documentation and packaging to do. And I'm pretty excited about carrying Cobra all the way to a 1.0 release this year!

Tuesday, February 27, 2007

Cobra 0.4 Released, "Why Cobra?"

Cobra 0.4 has been released:

Also, a Why Cobra? document has been added and Coding for Quality has been broken out so that it can be directly linked to (it's important).


Feedback is always welcome:
contact -AT- cobralang -DOT- com

Tuesday, February 20, 2007

Cobra Discussion and Upcoming Release

Some interesting discussion about Cobra is taking place at reddit. Of course, it includes the obligatory dismissal of any language that is new. :-)

The next release is in 2-3 weeks.

Tuesday, January 09, 2007

Truthfulness

Cobra copies a lot of syntax and high level semantics from Python, including how to determine truthfulness:

... if stuff
... ... print 'I have some stuff.'

(Sorry for the periods, but Blogger is stripping preceding whitespace. Maybe I'll have to find a new blog site. Suggestions are welcome.)

In Python, as well as the current release of Cobra, "stuff" is considered true if it is non-zero, non-nil, non-empty or the boolean value, true. So even empty strings and collections are considered false. That can be useful since programmers often want to take or avoid an action if a string is blank or a collection is empty. Code becomes more terse:

... if not name
... ... print 'You have no name'
... # vs:

... if name is not nil and not name.length

... ... print 'You have no name'


But that also introduces a lot of expressions in the form "stuff is not nil" either because that is exactly what you need, or for efficiency.

Keep in mind that determining "non-empty" involves inspecting the object to allow a method to partake in the determination ("__nonzero__" in Python; "length" or "count" in Cobra). That's expensive and so between that expense and the numerous "...is not nil" fragments in my code, I decided to reconsider this semantic.

Would it be better to drop the semantics regarding blank strings, empty collections and object participation in truthfulness? I wasn't sure, but felt that an examination of Cobra source code would be telling.

So I augmented the Cobra compiler to count the number of times a reference type was checked for truthfulness vs. the occurrence of "x is not nil". I then applied it to the largest Cobra project to date: the Cobra compiler. The counts came out:
  • 107 - instances of "x is not nil"
  • 509 - instances of simple truthfulness on reference types
So it would appear that high-level truthfulness is quite popular. But as part of doing the count, I printed the expressions that were being considered for their truthfulness.

And I was alarmed at how many of them should have been "is not nil" from an efficiency point of view. Basically, if you know that the type of an object does not customize truthfulness with the "count" method, then "x is not nil" is much more efficient than "x". That's because "x" implies checking the type (String, ICollection) and possibly checking for a "count" method.

I read though all 509 and counted the ones that should have used the simpler calculation of "x is not nil". That changed the numbers to:
  • 412 - x is not nil
  • 204 - truthfulness on reference types
Not only is "is not nil" a more popular computation (2 to 1), but the current approach leads to slower running programs if you're not diligent.

Furthermore, Cobra's compile-time nil tracking means that many variables cannot be nil anyway and therefore the expression:

... if s is not nil and s.length

becomes:

... if s.length

when "s" is a "String" rather than a "String?":

... def doSomething(s as String)
... ... # "nil" cannot be passed in for "s"
... ... # because its type is not "String?"


So I made the change and then updated the Cobra compiler source, test cases, samples and docs. This experience confirmed that the new semantics were usable, writeable, readable, in other words, capable. (Btw this is another advantage to writing a language's compiler (or interpreter as the case may be) in the language itself--you find out fairly quickly which ideas were good and which were bad.) This will show up in the 0.4 release later this month.

Regarding Cobra's ongoing development, there are certainly major additions in the future, for example, operator overloading. But this is the last change I know of that has a major impact on existing code.

Friday, November 17, 2006

New Compiler, New Computer

Yesterday, I released Cobra 0.2. This is the new compiler written in Cobra itself and delivered as a .NET exe (previous versions were Python programs).

Now Cobra will return to a fairly regular release schedule of once per month.

Today, I received a new MacBook Pro 17" 3GB Intel Core 2 Duo. It's bad to the bone. Assuming that Mono runs on it, all future Cobra releases will be tested on Novell Mono on Mac as well as Microsoft .NET on XP Pro. In fact, I plan on running a copy of XP Pro on Parallels on Mac OS X so I can literally use both operating systems at once. I'll have ready access to all that is Mac as well as Visual Studio 2005. Search the Internet and you'll find several existing blog posts of people doing this successfully. In fact, that was the tipping point for me to finally take the plunge into Mac.

By the way, I was a major NeXTstep user back in the day. It feels good to "come home."

Tuesday, November 14, 2006

Comparison to Python

I have added a Comparison to Python essay on CobraLang.com. This will help Python programmers understand the point of Cobra, including in contrast to IronPython.

Saturday, November 04, 2006

New Cobra Compiler

Regarding the new, upcoming Cobra compiler written in Cobra, it will be released this month (November). There will be some minor refinements to the language, improved error checking, faster compilation and the Python dependency will be removed.

I'm about 80%-90% of the way there. I'm really looking forward to getting back to pushing the features and maturity forward after this release.