Settings

Theme

Cobra language gets major update

cobra-language.com

48 points by whiletrue 13 years ago · 23 comments · 1 min read

Reader

Currently for .NET, JVM in the pipeline.

JackC 13 years ago

The docs aren't loading for me, but my first question was, why create a language that is almost, but not quite, exactly like Python syntax? Why give up compatibility with that whole community in exchange for minor syntax changes? (I don't mean the language extensions, like contracts, but the random tweaks that would stop you from running Python code directly in Cobra.) Here are some cached answers on that:

Why Cobra? http://webcache.googleusercontent.com/search?q=cache:A7djdaz...

and

Cobra compared to Python: http://webcache.googleusercontent.com/search?q=cache:GmrbTK9...

It sounds like basically the adoption strategy is to sell people coming from .NET on a Python-like language with binary compatibility, rather than to sell people coming from Python on a statically typed, compiled language with source compatibility. So, not as much for me as a Python person, until the ecosystem evolves. Too bad, because it doesn't seem like there was much of a win from giving up forward compatibility. But maybe a cool thing for .NET people?

  • reinhardt 13 years ago

    To make matters worse, there are no less than three Python-like options in the .NET world: IronPython, Boo and Cobra. With such fragmentation C# will probably stay the only game in town for a long time.

    EDIT: Apparently Boo hasn't been updated for almost a year.. sad. Oh well, that leaves two choices then.

    [1] http://dist.codehaus.org/boo/distributions/

    • whiletrueOP 13 years ago

      Python syntax is just one aspect of Cobra. There is also nil-checking, contracts, and easy syntax for testing.

  • whiletrueOP 13 years ago

    Cobra is compiled, there is a big speed difference compared to Python. There are a bunch of other features you should check out once the site speeds up.

    • klibertp 13 years ago

      > once the site speeds up.

      That means when the interest in the language drops to near zero again... I don't know, maybe the authors or maintainers of a web page should be warned before posting the link on Hacker News? I'm angry, because I find Cobra to be one of very nice languages that I'd like to see used more - and hn'ed site does not do any good on that front :/

      I was playing with Cobra about a year ago and it was promising then - now it looks like it's almost ready for prime time. I think I'll try to use it for my next project.

    • JackC 13 years ago

      I did check out the list of features, and it sounds very cool. I like the first-class support for contracts and testing. But it's like, if I have to learn new language quirks and find new libraries to do everything and so on, I could also spend time learning rpython, or go, or any number of other very cool projects with more established ecosystems. Cobra syntax looks so close to Python syntax that it might as well be a superset of Python and be able to run Python programs and take advantage of the Python ecosystem ... except it can't, because there are (what look to be, forgive me if I'm wrong) extremely minor incompatibilities like missing colons or alternate list comprehension syntax. That makes it ten times as annoying to pick up as a new tool, and just strategically, I question whether the gain from the incompatibilities was worth it.

      • klibertp 13 years ago

        As I understand it Cobra wants to take advantage of .NET ecosystem, it's libraries and all. If you are not into .NET then I guess you are right, but if you are willing to learn .NET or are already familiar with it, then Cobra may be a nice tool. I recently had to write a small library for .NET and used F# for this (I don't like C# and didn't want to use IronPython), but Cobra could be even better fit for what I needed to do.

        If you need Python on .NET there always is IronPython, which is quite well supported. I think Cobra was made incompatible with Python syntax to emphasize that it is not Python, it has different aims and philosophy - but I can be dead wrong on this, maybe it's just because author liked some syntax better...

        That being said I really don't think syntax matters that much, even if it's very similar (or very different) to something you know already. I learned and use CoffeeScript with pleasure even though it's syntax is similar - but not compatible - with Python's. Given a good syntax highlighting plugin for Vim, which I use as my editor, I have almost no problem at all with switching from Python to Coffee mode - when I end an if statement with ":" it gets highlighted as an object literal and then I instantly know it's wrong. On the other hand I use OCaml and Racket for some of my side-projects and similarly I don't miss much of Python's constructs. I think it is more important for syntax to be consistent than to be familiar or similar to something. I just don't understand marketing languages as "similar to C" in syntax, who cares?

        • pjmlp 13 years ago

          F# took over Python, when I am doing scripting on Windows.

          Just because it is a nice excuse to use it on work projects, otherwise I am bound to the languages required for the project.

          • klibertp 13 years ago

            That's true, it's hard to use something different at work and F# seems plausible as a tool enough to use it without risk :)

thomasz 13 years ago

This looks promising. Nothing that has never been done before, but I really like the support for baked in doctests and contracts. This kind of sugar can make a real difference in terms of quality and readability

    #from the website, because it seems to be down for many right now.

    class SmallSample
	var _random = Random() 
	def randomString(length as int, alphabet as String) as String
		require
			length > 0
			alphabet <> ''
		ensure
			result.length == length
		test
			utils = SmallSample()
			assert utils.randomString(5, 'ab').length == 5
			s = utils.randomString(1000, 'a')
			for c in s, assert c == 'a'
		body
			sb = StringBuilder()
			for i in length
			c = alphabet[_random.next(alphabet.length)]
			sb.append(c)
			return sb.toString
  • darkstalker 13 years ago

    On that example, the syntax looks like Python with a bit of BASIC (the type declarations). That "StringBuilder" object reminds me of Java, I would prefer a concatenation operator.

    Seems that doesn't use explicit variable declaration. Supporting that would be a great improvement over Python.

    • yogo 13 years ago

      It has explicit variable declaration. You can always do: varname as Type = expression

      You often won't see this for the sake of succinctness. I might have misunderstood what you were saying but thought I'd mention that.

  • jksmith 13 years ago

    I've always wanted to work with a language that supports contracts (originally Eiffel I guess). Would love to see this hacked into Go. Or maybe I shouldn't turn this into a Go thread and start using Cobra.

jcheng 13 years ago

Looks a lot like boo[0], which has been around for about a decade and has a Python-like syntax, type inference, static+dynamic typing, REPL loop, and runs on the CLR. Fantastic language, especially when it was new and C# was missing many of the features boo offered.

From what I can tell, Cobra adds compile-time nil tracking (nice!) and contracts. I'd be extremely interested in this if I was still doing anything in .NET.

[0] http://boo.codehaus.org

  • stephen 13 years ago

    Boo is awesome; it's meta-programming/macros look awesome.

    Selfishly, I wish the JVM was its primary target and not .NET.

tomku 13 years ago

The syntax reminds me of a mixture of VB and Python, but it certainly seems to have a lot of interesting features that you don't see together often. Anyone here have experience using it?

pjmlp 13 years ago

This is what Go should have been.

Seems quite nice.

creatio 13 years ago

Am I the only one who read it as: The Clean Language (as in the functional languagel CLean) and powerful Cobra Language gets major update.

whiletrueOP 13 years ago

Sorry guys, looks like the site is a little slow right now...

m1 13 years ago

Had to do a double take then, thought it said Cobol

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection