Page 1 of 2

How to start with Cobra

PostPosted: Tue Dec 07, 2010 5:40 am
by archeopteryx
Hello,

I'm a newbie, and not confident with computer terminology. I'd appreciate some help getting started with Cobra.

I run WinXP. I've got .NET installed, as well as the free version of Visual Studio 2010 (and C# etc...). I've downloaded Cobra-2010-10-18.zip and unzipped it in C:\Program Files\Cobra Now how do i use it?

I gather Cobra doesn't come with an IDE? And I gather there isn't a preferred editor? Can i use Notepad for now, to test the water? If so, will it matter that a tab consists of 8 spaces? After i've typed my source, where's the best place to save the file (eg HelloWorld.cobra)? Is C:\My Documents\Cobra Projects (for eg) fine? Do i need to create environment variables? Do i add anything to my path? How do i compile the program? And finally, how do i run it?

Could someone pls walk me through those steps in a didactic straightforward way? I should be able to get the hang of it from there.

Thank you,

archeopteryx

Re: How to start with Cobra

PostPosted: Tue Dec 07, 2010 9:55 am
by Charles
Cobra works fine on Windows XP.

If you look at the files you unzipped there should be a "read me" with further instructions on setting up Cobra. Basically, do not unzip to "Program Files" yet because it's not ready to run. Instead, unzip somewhere else and, from the command line, run the install-from-workspace.bat command in the Source\ subdirectory. The "read me" covers this.

The end of the installer will tell you about the path to the Cobra executable. And yes it helps immensely to either add Cobra to the path or take the "cobra.bat" file and put it somewhere in your path.

You can use Notepad. Tab setting doesn't matter in the short term. We have a plugin for Visual Studio 2010 Pro and expect to have a free "Visual Cobra Express" probably this month or next. In the mean time we have wiki pages for EditorSupport and IDESupport.

I think you will have a much better experience using something other than Notepad so that you can get syntax highlighting. There are multiple free editors that can do this documented in the wiki. I would move from Notepad as soon as possible.

A "Cobra Projects" directory in your "My Documents" directory is a fine place to save your files.

Regarding compiling and running, these are straightforward and covered at CommandLine.

Let us know how it goes.

Re: How to start with Cobra

PostPosted: Tue Dec 07, 2010 12:59 pm
by archeopteryx
Thanks Charles.

I've done the first couple o' steps and anticipate a smooth course thro editors, compiling etc..

archeopteryx

Re: How to start with Cobra

PostPosted: Wed Dec 08, 2010 4:16 am
by archeopteryx
Something else i'm unsure about...

1 I saved Cobra-2010-10-18.zip in My Documents\downloads\cobra and unzipped it into the same folder.
2 This created a new folder, Cobra-2010-10-18, with subfolders: developer, how to, reusables, etc.
3 I then executed install-from-workspace, which automatically created c:\Cobra with subfolders called bin and Cobra-0.8.0-post (which in turn has subfolders called bin, how to, reusables, samples, supplements - which appear to be the same as the corresponding folders in #2 above, minus the folders called SamplesInProgress, source, tests)

Is all this correct?
Do i need to keep Cobra-2010-10-18?
Can i simply move SamplesInProgress, source, tests to C:\Cobra\Cobra-0.8.0-post and delete My Documents\downloads\cobra\Cobra-2010-10-18?
Or are they all meant to stay put and work together?

Thank you for educating me!

archeopteryx

Re: How to start with Cobra

PostPosted: Wed Dec 08, 2010 8:50 am
by Charles
What you did is correct and has resulted in:

(a) Installer package files in My Documents\downloads\cobra

(b) Installed files in C:\Cobra

One might remove (a) after installation. Since you have expressed an interest in source files like Source and Tests, you can leave (a) in place. If you would prefer to copy select subdirectories over to the installed directory and then delete remaining (a) files, you can try it. I don't think it will hurt anything, but I haven't done it before.

For myself, I typically have a Subversion workspace (or several) lying around which I install from. Installing changes my "system-wide" Cobra which remains in place until I run an installation again. The package you installed is a copy of a workspace at a stable point in time. See HowToInstallFromSource if you're interested in that, but it's not a requirement.

In terms of learning Cobra for the first time, I think the How Tos, Samples and Wiki are your best initial sources, coupled with asking questions here. After that, there is the test suite although those programs can be rather arcane so I don't recommend starting there.

Re: How to start with Cobra

PostPosted: Sun Dec 12, 2010 1:47 am
by archeopteryx
Alas, i think i need a bit more education....

I saved SciTE in C:\Program Files\wscite, overwrote SciTEGlobal.properties, and saved cobra.properties and cobraproj.properties. Is this what i should've done?

I wrote Hello.cobra in the editor, and saved it in C:\Cobra\Cobra-0.8.0-post\Samples

Back in the editor, i performed Tools | Go (f5), and got:
>C:\Cobra\bin\cobra.bat "C:\Cobra\Cobra-0.8.0-post\Samples\Hello.cobra"
Hello!
>Exit code: 0

Back in ....\Samples i found Hello.exe, but i couldn't see what was displayed cos the command prompt flashed shut almost immediately.

I deleted Hello.exe, went back to the editor, and performed Tools | Build (F7), and got:
>C:\Cobra\bin\cobra.bat -c -turbo "C:\Cobra\Cobra-0.8.0-post\Samples\Hello.cobra"
Compilation succeeded
>Exit code: 0

Back in ....\Samples once again, i found a new Hello.exe - and again i couldn't see what was displayed cos the command prompt flashed shut almost immediately.

I deleted Hello.exe, went back to the editor, and performed Tools | Compile, but this time i got:
>C:\Cobra\bin\cobra.bat -c -files:"C:\Cobra\Cobra-0.8.0-post\Samples\Hello.cobra"
cobra: error: Cannot find "C:\Cobra\Cobra-0.8.0-post\Samples\class Hello" as a file.
Run Cobra without options to get full usage information.
>Exit code: 1

And no Hello.exe was produced in ....\Samples

My questions are:
[*] how do i keep the command prompt open when i run the .exe, till i'm ready to close it?
[*] why do both "run" and "build" create exe's? (I assumed "run" invoked an interpreter.)
[*] how does "build" differ from "compile"?

Just out of curiosity, is it possible to get the editor to display the same colours and syntax highlighting as on Cobra's homepage? I really like it!

Thanks for any guidance,
archeopteryx

Re: How to start with Cobra

PostPosted: Sun Dec 12, 2010 8:38 pm
by torial
archeopteryx wrote:Alas, i think i need a bit more education....

I saved SciTE in C:\Program Files\wscite, overwrote SciTEGlobal.properties, and saved cobra.properties and cobraproj.properties. Is this what i should've done?

Yes. You did this correctly.

archeopteryx wrote:I wrote Hello.cobra in the editor, and saved it in C:\Cobra\Cobra-0.8.0-post\Samples

Back in the editor, i performed Tools | Go (f5), and got:
>C:\Cobra\bin\cobra.bat "C:\Cobra\Cobra-0.8.0-post\Samples\Hello.cobra"
Hello!>Exit code: 0

Back in ....\Samples i found Hello.exe, but i couldn't see what was displayed cos the command prompt flashed shut almost immediately.

The area that I hilited in red above is the actual output of the Hello.cobra application. I'm presuming this showed in the output window (it may be called output pane, I can't remember) of SciTE (this is where it normally shows for me) - please confirm.

archeopteryx wrote:I deleted Hello.exe, went back to the editor, and performed Tools | Build (F7), and got:
>C:\Cobra\bin\cobra.bat -c -turbo "C:\Cobra\Cobra-0.8.0-post\Samples\Hello.cobra"
Compilation succeeded
>Exit code: 0

Back in ....\Samples once again, i found a new Hello.exe - and again i couldn't see what was displayed cos the command prompt flashed shut almost immediately.

Typically I work w/ the output window of SciTE, but if you want to do it via command prompt, then Start | Run | cmd
Then paste in the app path (usually right-click, but you may need to do it via the menu depending on how you've configured CMD) and hit enter. (I hope I'm not being too pedantic, but if so, please ignore, also this may answer your first question below.)

archeopteryx wrote:I deleted Hello.exe, went back to the editor, and performed Tools | Compile, but this time i got:
>C:\Cobra\bin\cobra.bat -c -files:"C:\Cobra\Cobra-0.8.0-post\Samples\Hello.cobra"
cobra: error: Cannot find "C:\Cobra\Cobra-0.8.0-post\Samples\class Hello" as a file.
Run Cobra without options to get full usage information.
>Exit code: 1

And no Hello.exe was produced in ....\Samples

This may be a bug in my configuration for the cobra.properties (e.g. it looks like I stomped over the original settings w/ the cobraproj settings). A cursory look at my cobra.properties file isn't showing the -files: flag showing up (only in cobraproj.properties). I will look into that, but it may be a few days as work is quite hectic. Did you create a cobraproj file by any chance?

archeopteryx wrote:My questions are:
[*] how do i keep the command prompt open when i run the .exe, till i'm ready to close it?
[*] why do both "run" and "build" create exe's? (I assumed "run" invoked an interpreter.)
[*] how does "build" differ from "compile"?

Just out of curiosity, is it possible to get the editor to display the same colours and syntax highlighting as on Cobra's homepage? I really like it!

Thanks for any guidance,
archeopteryx


Build / Run both generate an exe since there is no interpreter. Run is just the Build step coupled with the execution of the application.

Build differs from Compile in that Build occurs with the "-turbo" flag, which means that unit tests and contracts are NOT run. Compile doesn't have that flag so will run any unit tests or contracts you define.

Regarding the syntax highlighting color... if Charles or Todd can point me to the color definitions for the categories they used I'll see what I can do to make it more synchronized (this would likely be done next weekend at the *earliest*). I believe this could be using the pygments highlighter but will wait for confirmation ;-)

Re: How to start with Cobra

PostPosted: Sun Dec 12, 2010 9:58 pm
by Charles
Actually the highlighting on the front page was done "the hard way" so you can just look at the HTML and stylesheets.

Thanks for the followup, torial.

Re: How to start with Cobra

PostPosted: Mon Dec 13, 2010 4:14 am
by archeopteryx
torial wrote:Yes. You did this correctly.

OK, thanks.

torial wrote:The area that I hilited in red above is the actual output of the Hello.cobra application. I'm presuming this showed in the output window (it may be called output pane, I can't remember) of SciTE (this is where it normally shows for me) - please confirm.

Yes, that's correct.

torial wrote:Typically I work w/ the output window of SciTE, but if you want to do it via command prompt, then Start | Run | cmd Then paste in the app path (usually right-click, but you may need to do it via the menu depending on how you've configured CMD) and hit enter.

Oh... OK... i was just double-clicking Hello.exe (actually, the little rectangular graphic with the blue horizontal "ribbon" up top, that Win uses to signify an executable). It was this that caused the windowed "DOS prompt" to flash open and shut. In other languages, this behaviour is prevented by coding some sort of "wait", "pause", or "get_next_char" function. Not so in Cobra?

torial wrote:This may be a bug in my configuration for the cobra.properties. Did you create a cobraproj file by any chance?

No, just a single Hello.cobra file with 3 lines of code.

torial wrote:Build / Run both generate an exe since there is no interpreter. Run is just the Build step coupled with the execution of the application. Build differs from Compile in that Build occurs with the "-turbo" flag, which means that unit tests and contracts are NOT run. Compile doesn't have that flag so will run any unit tests or contracts you define.

Oh, OK... i see.

Thank you very much for your patience and help.

archeopteryx
PS: regarding the colours on the web page, i just happen to find them very appealing. i think i could code in Cobra just for the pleasure of seeing that colour combination appear on my display! :-)

Re: How to start with Cobra

PostPosted: Mon Dec 13, 2010 12:09 pm
by torial
Hey Charles -- in the styles-cobra-shl.css, can you give me an example of the "literal string right bracket" and "literal string left bracket"?

Nevermind, I realized that was the variable interpolation brackets.