Notifications
Clear all

[Closed] maxscript syntax comparison

I feel like I’ve hit a plateau with regards to programming concepts, so I decided to start learning other programming languages in the hopes that I’d be introduced to different ways of thinking and solving problems. For example, I really didn’t understand structs in maxscript until I coded my first class in python – and then my head exploded (in a good way).

     So I started putting together 'comparisons' of different language's syntax... with suprising results (to me at least).  I was not aware that Python doesn't have a do/while loop, a case statement, or the ability to forward declare functions.  Please correct me if I'm wrong.
     
     Would everyone agree on the comparisons below?
     Here's the first one done, correct me if you see any errors - I'm new at this:

(updated 2011.04.29)

Here is link to larger version. Here is link to original version 1.

    Hopefully someone else finds this educational as well! 
 
 This also raised some questions regarding maxscript:
 1.  Does maxscript have 'constants' like C?  example: #define myConstant 1000
 2.  Is there an equivalent to '#include' in maxscript, or would this just be fileIn()?
 3.  Can you set the size of an array in maxscript?  If so, does this increase performance?
 4.  Is there any benefit to [manifest typing]( http://en.wikipedia.org/wiki/Manifest_typing)  in maxscript?  Is there any performance difference between that and implicitly/dynamically typed code?

I apologize if any of these are silly questions. Thanks!

13 Replies

No. Or if it is, it is very well hidden.

  1. Is there an equivalent to ‘#include’ in maxscript, or would this just be fileIn()?
    fileIn or include is probably the closest thing to #include in C.
  1. Can you set the size of an array in maxscript? If so, does this increase performance?
    Yes, if you’re dealing with large arrays, it might be beneficial.

(
  local arr = #();
  arr[250] = 0;
)

Also see the maxscript help -> How to make it faster -> Pre-initialize arrays when final size is known.

  1. Is there any benefit to manifest typing in maxscript? Is there any performance difference between that and implicitly/dynamically typed code?
    maxscript doesn’t support explicit typing. The performance hit generally comes from casting (implicit or explicit), although I’m not sure how large the impact is in maxscript, since it is a dynamically typed language. It could be interesting to run some tests on that

Btw, your maxscript ‘main fn’ has a syntax error Comments should be –do stuff.

  1. In Maxscript, it is same “include”.

[left]include <filename_string>
[/left]
[left]Inserts the specified file’s content into the Listener output pane. The inserted text is not evaluated. You can use this method to load a script and then step through it, executing any selected text with SHIFT+ENTER. <filename_string> is a string literal or an expression that evaluates to a string, and specifies the name of the file to insert.
[/left]

http://www.amazon.com/Concepts-Techniques-Models-Computer-Programming/dp/0262220695
This book is great if you want some good literature on programming concepts.

@Pjanssen: thanks for the reply! Now I’m seeing all kinds of syntax errors in the image.

@gandhics: Awesome! I was not aware of include in maxscript.

@haavard: sweet! ordering it rite now. (Estimated delivery May 2, 2011 – May 6, 2011)

*In the case of MAXScript, i++ does nothing (causes a syntax error). You have to use i+=1 instead (in the while loop).
*The typical way to write that case of() example would be

case c of
 (
 1: print "Case 1"
 2: print "Case 2"
 3: print "Case 3"
 default: print "This is the default"
 )

Your code is not wrong, and if each case had a different comparison, it would be the only valid way to write, but when comparing c to 1,2 and 3, the above is cleaner.

*The forward declaration of a function does NOT require a FN constructor at all, you can just declare a variable that will hold a function later.

So you can say

(
 local someFunction
 fn mainFunction param1 =
 (
 someFunction param1
 )
 fn someFunction param1 =
 (
 format "Parameter was %
" param1
 )
 mainFunction "Test"
 )
 

The forward declaration of the second function’s variable will make it accessible to the first function even if the first function does not see an actual function definition at the time of evaluation. At run time, the variable will contain a function already and everything will be peachy.

  1. Nope, there are system globals and reserved read-only globals which are KIND OF like constants, but there is no concept of constants in MAXScript and you cannot make your own. For example
pi
 3.14159
 pi=10
 -- Cannot assign to read-only variable: pi
  1. include() in MAXScript inserts the string stream of the specified file into the stream being parsed before the evaluation, while filein() is equivalent to opening a file and evaluating it in global scope. Check out the MAXScript Reference for details.

  2. Yes, by setting the last element to any value (even undefined). I use this a lot (and it is mentioned in the “How to make it faster” topics in the Help). Pre-initializing the array or bitarray means that the memory is allocated once and this can reduce the memory allocation overhead at run time.

a = #()
 --> #()
 a.count
 --> 0
 a[10000]=undefined
 --> undefined
 a.count
 --> 10000 
 --at this point, the array has 10000 undefined entries you can populate by index later. 
 --Using append() will have to grow the array eventually, so it tends to be slower.
  1. MAXScript is type-free so you actually cannot pre-declare the type of a variable. It can change at any time, which is a curse and a blessing, depending on the situation. It might be a good idea to name your variables respectively to inform yourself and others what is expected to be stored in each variable, and probably use asserts to check that the type of the variable is what is expected…

@Bobo: You’re awesome! Are there any books/advice you would recommend for a young aspiring coder?

Hey man, there are two great video sources that I recommend you to check out:
MIT open courseware

Google Class

I really liked your sintax chart idea, by the way =)

My two cents
cheers

@Polimeno: MIT open courseware looks really interesting! I’ll be watching those videos for a few days.

I really liked your sintax chart idea, by the way =)

Awesome! I’m working on another version (fixed syntax errors, expanded to include C#, better organization) that I’ll post soon.

Wouldn’t C# be the same as C, with a few very minor exceptions?
An interesting one to include might be private/public keywords for structs by the way. Not that it differs between mxs and C, but still

Page 1 / 2