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
249
> 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
249
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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top