From JASS to Python

Bribe

vJass errors are legion
Reaction score
67
Fed up with the JASS interpreter and onto professional programming envirnoments, I've been studying Python. Yes, I know it is also an interpreter, but the far greater capability and compatibility squash a JASS script.

I have a few specific questions;

An array in JASS is comparible to what in Python? Dictionary or List? I'm confused how to most efficiently iterate through them and reference specific array slots.

Is there a way to deallocate lists and tuplets and other storage utilities to free up RAM?

What kinds of whitespace is permitted? Can I use spaces as well as tabs? How many spaces need to be inserted to register as a block? I know that four-spaced tabs are allowed, but can I use 2, 6 or higher, if deemed necessary? I know I can join lines by adding an \ operator, but can I combine two statements on one line by adding a ; operator?

Any general advice you can give a programmer switching from JASS to Python? I know everything there is to know about vJass' added features and Zinc's compile-time differences, as well as pretty much everything there is to know about JASS.
 

Vestras

Retired
Reaction score
248
> Is there a way to deallocate lists and tuplets and other storage utilities to free up RAM?

I'm not too fund of Python, but generally in "real" programming languages you don't have to worry too much about RAM, because there are garbage collecters. Not sure if this applies to Python, though.
Else the List/Dictionary classes probably have a Dispose method.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
An array is comaparible to a list, but lists are much more powerful.
Think of a dictionary as an associative array, or even a hashtable.

As for deallocating, Python should handle that for you.
Whitespace is actually rather important. Instead of braces ({}), Python uses tabs to define codeblocks. For example,

Code:
def HelloWorld():
    print "Hello World!"

Would be this,

JASS:
function HelloWorld takes nothing returns nothing
    call BJDebugMsg("Hello, world!")
endfunction


in JASS.
Notice how instead of braces (or end*) , the Python script used whitespace.

Edit: The Python manual has excellent documentation on what lists, dictionaries and tuples can do: http://docs.python.org/tutorial/datastructures.html
 

Artificial

Without Intelligence
Reaction score
326
> Can I use spaces as well as tabs?
Each file has to use either tabs or spaces, you may not mix them. Would be impossible to read both for humans and for the machine.

> How many spaces need to be inserted to register as a block?
As many as you want. The amount has to be consistent throughout the file, though. And I think there is a minimum of 1. ^_^

> can I combine two statements on one line by adding a ; operator?
It being insanely hard to test, I'll tell you: yes. I've never needed that functionality for anything, though.
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
Dude you are rushing...
I think the transition should be Jass2 -> Perl -> Python -> [your own scripting language] -> asm (jk xD)

Anyway Python is really awesome with it's blocks delimited by spaces! That sure boosts code readability/maintaining.

Hell it's even used by NASA.
 

Bribe

vJass errors are legion
Reaction score
67
Thanks everyone for your tips; I haven't downloaded it yet because I just moved, but I burned through the Python pocket booklet I got a few days ago and I still had those questions unanswered.

Mutable and immutable seem like strange words to me; I imagine handles are mutable in JASS while others not? No idea, but I really don't think that is important to know.

These bytes and bytarrays seem extremely pointless, as well as using Octal integers instead of 16 bit hex or 32 bit integers... coming from a JASS background, of course.

Again, thanks!
 

celerisk

When Zerg floweth, life is good
Reaction score
62
Why would anyone ever want to learn Perl?

Excellent question.
Strangely enough, one possible answer is "job security" (yep, Perl, somehow, is still in the top 10 asked for languages).
('course, another factor for job security is the simple fact that once your Perl "code" is deployed, no one else will ever be able to do any edits to it :D)
 

Vestras

Retired
Reaction score
248
Thanks everyone for your tips; I haven't downloaded it yet because I just moved, but I burned through the Python pocket booklet I got a few days ago and I still had those questions unanswered.

Mutable and immutable seem like strange words to me; I imagine handles are mutable in JASS while others not? No idea, but I really don't think that is important to know.

These bytes and bytarrays seem extremely pointless, as well as using Octal integers instead of 16 bit hex or 32 bit integers... coming from a JASS background, of course.

Again, thanks!

You'll figure out why they're useful, especially 16 bit (short), 32 bit (int) and 64 bit (long) integers. Basically the use depends on what you need and how much RAM you wish to allocate.
Bytes are 8 bit integers, the C++ equivalent of char.

Excellent question.
Strangely enough, one possible answer is "job security" (yep, Perl, somehow, is still in the top 10 asked for languages).
('course, another factor for job security is the simple fact that once your Perl "code" is deployed, no one else will ever be able to do any edits to it :D)

Bleh, Perl isn't code, it's noise. I suppose that's why no one can edit it? :p
 

lep

Active Member
Reaction score
8
Someone who probably never even touched any perl writes that perl is shit.
Perl is one of the most excellent languages. Everything you can do in some language you can do in perl.
And only noobs write *typical* perl-code.
Perl can be, if written correctly, the most beatifull language.

But yeah, perl is free and so needs an free mind. Some people just need a strict set or rules (oh wait, perl can do that too. use strict;).

http://www.bofh.org.uk/2010/07/25/a-tale-of-two-languages
 

SerraAvenger

Cuz I can
Reaction score
234
Perl is one of the most excellent languages. Everything you can do in some language you can do in perl.
By this definition, Ook is one of the most excellent languages.

Perl is great for hacks!
Hacks are great for... for...
I'm sure they're good for something.


And only noobs write *typical* perl-code.
This makes code messy by definition. I'm glad that no individual style has emerged in the go world.
In ruby, there is only individual styles, and I can still read everything. I'm not sure others can, though. On the other hand, there are certain policies and conventions that I haven't seen broken yet. This is why operator overloading works so great in the ruby community.
In python, on the other hand, I haven't seen a similar thing. I have seen very fascinating examples of how not to do error handling while glancing at python code. In ruby, there is only raise-catch expception handling. In go, there is only return codes (and panics, when you HAVE to panic). In python, I have seen both - within the same code, at times - for the same sort of error. It was awkward.

Perl can be, if written correctly, the most beatiful language.
I agree that it is a very beatiful language. I always beat others who develop in perl.
Seriously though, perl CAN be written in a beautiful way. I haven't seen a true ruby program that wasn't beautiful.

But yeah, perl is free and so needs a free mind.
Wait, what? It must be written correctly, but needs a free mind?

Some people just need a strict set of rules (oh wait, perl can do that too. use strict;).
Sounds hacky. I think I already said what I'm thinking of hacks?

>Mutable and immutable seem like strange words to me
There's lots of things that are very interesting out there. When you know Zinc/vJASS/JASS and think you know about programming, you're currently on the titanic and think you know the iceberg.
You should start with other OOP languages (python is ok, I don't like it myself), Ruby is very interesting (In ruby, there is no single/correct way, that's a lot of freedom - but power comes with responsibility!).
Languages like C/C++ (I guess I just killed a kitten), html,php&javascript or go/erlang should be somewhere on your roadmap, too.
Depending on what you want to achieve and where you want to go, that is.
 

celerisk

When Zerg floweth, life is good
Reaction score
62
"Beauty is in the eye of the beholder"


While some Perl code, somewhere, might look like this:
Code:
#!/usr/bin/perl

use strict;

# opens file for writing; overwrites contents if file already exists
open(OUT, ">fileio.txt") or die "Cannot open fileio.txt";
print OUT "hello\n";
close(OUT);

# opens file for writing in append mode
open(OUT, ">>fileio.txt") or die "Cannot open fileio.txt";
print OUT "world\n";
close(OUT);

# opens file for input
open(IN, "<fileio.txt") or die "Cannot open fileio.txt";

# "slurps" file into an array using newline as separator.
my @lines = <IN>;
close(IN);

print $lines[1];


Advanced Perl coders are more likely to produce something like this:
Code:
perl -l -e '(1 x $_) !~ /^1?$|^(11+?)\1+$/ && print while ++$_;'

This second example is clearly Perl, clearly beautiful... but, well, do you get what it is doing just from looking at it?




Random rant: HTML is NOT a programming language.
 

tooltiperror

Super Moderator
Reaction score
231
HTML is a markup language, and therefore, by loose definition, a programming language. To call someone who uses it a programmer or to call it a decent language is a different thing.

Also, here's some almost equal examples.

vJASS
JASS:

// This is a comment.
 library HelloWorld initializer OnInit
   private function OnInit takes nothing returns nothing
       call BJDebugMsg(&quot;Hello, World!&quot;)
   endfunction
 endlibrary


C# (Notice that a regular function is a method.)
Code:
// This is a comment.
public class Hello1
{
   public static void Main()
   {
      System.Console.WriteLine("Hello, World!");
   }
}

Lua (Notice it is being executed by the shell.)
Code:
-- This is a comment.
#!/usr/bin/lua
print ("Hello World!")

Ruby
Code:
# This is a comment.
puts 'Hello world'

In my unprofessional opinion, I highly recommend C#. Some people may disagree with it, specifically because it does have flaws.
  • MonoDevelop support for cross platform development is still in the distant future, and C# and the .NET Framework are still only for Windows. Then again, programming in other languages may be shit for cross platform.
  • Possibly slower than C or C++. Although probably not noticable, C# is built on C/++, therefore it may run slower in theory, although I can't talk from experience.
  • I think the constructors are ugly, period. The syntax looks like shit, and I'd prefer a method constructor to return the class, rather than the [LJASS] new Object[/LJASS] syntax.

Of course, C# also has it's advantages.

  • If you can Drag and Drop, with Visual Studio Express, you can create amazing GUI's in a few days, with easy event management and very customizable.
  • The complete OOP syntax is nice, all functions are methods, usually static, from objects like [LJASS]Math, System, Console, String,[/LJASS] and so on.
  • Chances are, if you're like almost all other C# Developers, you'll be using Microsoft Visual Studio Express 2010 C#. In other words, a beautiful IDE. It's great.
  • I felt an easy transition from JASS, personally.

If you're fine with limiting yourself to Windows for now, then I say go for C#.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top