Author Topic: NWScript & C - the relation  (Read 1929 times)

Telkar

  • Dark Power
  • ******
  • Posts: 1621
NWScript & C - the relation
« on: March 05, 2011, 08:25:07 PM »
So I've recently been dabbling into some programming languages, looking for one to develop some skill in. I decided to study python, and have been doing so for maybe a week or more. It has been giving me a nice superficial overview of some common programming practices. However, I believe that to acquire a really good understanding of a language, I need to have some great incentive to actually put the knowledge to use, learn from mistakes and keep pushing on to look for ways to solve my problems.

So that's when I figured something like scripting in NWN (game I love), could well give me that incentive. Then I found out that NWScript is based on the C language.

So I want to ask you nwn scripters out there: Is NWScript enough like C to provide a good practice in the C language? Would it give me a good insight into C?

Axel

  • Eternal Saviour/Community Council
  • Administrator
  • Dark Power
  • *
  • Posts: 1530
Re: NWScript & C - the relation
« Reply #1 on: March 05, 2011, 09:49:35 PM »
Not really. Even though the syntax of NWScript is allmost identical to the syntax of C, allmost all the things that makes C a powerfull language, are missing.

For example, there are no pointers in NWScript, which is most likely a good thing. Pointers allow you to access memory, and to build more complex data structures. It's also the most common source of errors in a program written in C. NWScript is designed for safety, so they didn't include pointers.

I guess NWScript is an okay start, if you want to learn to program, but you'll never get very far with it. It won't take long until you're straining against the boundaries, trying to make workarounds for something that, in a normal programming language, should be straight forward.

DM Nocturne

  • Sanguis Noctis
  • Dark Power
  • ******
  • Posts: 3262
  • Vampires don't do dishes
Re: NWScript & C - the relation
« Reply #2 on: March 05, 2011, 10:35:19 PM »
Studying Java myself, which is also a bit like NWScript.

The Prophet of Lies

  • Messianic Jackass / Ego Overmind / Clubber of Seals / Jumpropes with the intestines of forsaken orphans
  • Developers
  • Dark Power
  • *
  • Posts: 1556
  • The Forever #Trigger
Re: NWScript & C - the relation
« Reply #3 on: March 06, 2011, 12:56:49 AM »
Quote
For example, there are no pointers in NWScript, which is most likely a good thing. Pointers allow you to access memory, and to build more complex data structures. It's also the most common source of errors in a program written in C. NWScript is designed for safety, so they didn't include pointers.

DYNAMIC MEMORY ALLOCATION? VOICES IN HEAD.
"The brave man inattentive to his duty, is worth little more to his country than the coward who deserts in the hour of danger."
~Andrew Jackson


Telkar

  • Dark Power
  • ******
  • Posts: 1621
Re: NWScript & C - the relation
« Reply #4 on: March 06, 2011, 07:23:40 AM »
Not really. Even though the syntax of NWScript is allmost identical to the syntax of C, allmost all the things that makes C a powerfull language, are missing.

For example, there are no pointers in NWScript, which is most likely a good thing. Pointers allow you to access memory, and to build more complex data structures. It's also the most common source of errors in a program written in C. NWScript is designed for safety, so they didn't include pointers.

I guess NWScript is an okay start, if you want to learn to program, but you'll never get very far with it. It won't take long until you're straining against the boundaries, trying to make workarounds for something that, in a normal programming language, should be straight forward.

Thanks for the response. What about the other way around...is knowing C... or Java a much better way to get the hang of NWScript than knowing python for example? Or would NWScript be fairly easy to grasp if you know programming in general, such as when you jump from one programming language to another?

Just want to know if C/Java would get me a significant headstart there. I guess it wouldn't matter much though, as I got it into my head sort of to learn C after python.

Axel

  • Eternal Saviour/Community Council
  • Administrator
  • Dark Power
  • *
  • Posts: 1530
Re: NWScript & C - the relation
« Reply #5 on: March 06, 2011, 08:40:55 AM »
Well, any new programming language is fairly easy to grasp once you know one, but there are more similarities between C and NWScript than there is between Python and NWScript.

I'm not sure I would recommend an object oriented programming language as the first language though. They have yet another layer of abstraction and encapsulation, that are hard to use without having some notion of object oriented design. For that matter, I'm not sure I would recommend C as the first language either. ;)

Here are some pros and cons of the different languages:

C is perhaps one of the dirtiest languages around. You can do anything you want to do, but it's easy to make mistakes, and mistakes are punished severely. C is great for programming operating systems, low level drivers, protocol stacks, etc, not so great for large projects involving many programmers.

Java uses C syntax for simple statements, but removes some of the powerfull features of the language, and adds other features. It's an object oriented language, so there is a level of data encapsulation that is great for larger project. Compiled Java code can not run (natively) on a computer, but can be executed in a Java runtime environment, that is a virtual computer that runs on your normal computer. This construction gives Java great portability, since you can get a Java runtime environment for a lot of different computer architectures. So you can write one program, and it will run on a windows machine, a Linux machine, a Unix server, etc. Perhaps the greatest boon of Java is the extensive and well documented library. Java is great for writing flashy programs that manipulates data slowly, e.g. word processors, graphical interfaces for other programs, etc.

If I remember correctly, then Python is a scripting language. That means that the program is not compiled into an executable, but an interpreter reads the program at runtime and executes the instructions. This gives Python the same cross platform capabilities as Java, since you can get interpreters that run on almost any hardware and/or operating system. Python is an object oriented language, and is the language of choice for scripting for games, i.e., the main engine is usually written in C or C++, and the programming that has to be done for the individual levels is done using Python. I've heard good things about Python, but I haven't used it myself.

If I should recommend a path that would make you a competent programmer I'd say something vague along the lines of:
Learn C. Then read some books about object oriented design and object oriented programming. Then learn Java or C++. (Iterate until competent.)

If you "just" want to script for NWN I'd recommend you start scripting using NWScript.

Quote
For example, there are no pointers in NWScript, which is most likely a good thing. Pointers allow you to access memory, and to build more complex data structures. It's also the most common source of errors in a program written in C. NWScript is designed for safety, so they didn't include pointers.

DYNAMIC MEMORY ALLOCATION? VOICES IN HEAD.
But, is it (thread-) safe?

Telkar

  • Dark Power
  • ******
  • Posts: 1621
Re: NWScript & C - the relation
« Reply #6 on: March 06, 2011, 10:17:59 AM »
I've done a lot of research on what people are recommending as a starting language, and python seems to stand out the most. I'm grasping it alright so far, being well readable and all. But I guess we'll see what route I'll take. The routes people take seem pretty varied, based on what they're going to program and personal preference. So at the moment I'll definitely keep an eye on C as I study python some more.

And NWScript isn't exactly important to me, but I thought it'd be a fun way of learning C, if it'd help in that.

Thanks for the info. I'll keep it in mind for future reference.  :)

vlowe72

  • Undead Master
  • ****
  • Posts: 402
  • If you bore me, I shall take my revenge.
Re: NWScript & C - the relation
« Reply #7 on: March 06, 2011, 02:02:56 PM »
The syntax in NWN script is virtually identical to c++, so to learn one is to learn the other.  Java is very similiar to C++.  (Javascript is a web scripting language and is not the same thing as Java)

I have not actually tried to declare classes in NWN script, so I'm not sure if that would work, which would mean a big difference in that regard.  You can declare C type structures.  Pointers are also right out, which I can understand.  Pointers are the plutonium of the programming world; very powerful but dangerous in the hands of the inexperienced.

If I was to recommend a first language, I'd recommend PASCAL.  Now before you laugh... PASCAL is very similiar to Java in syntax, and doesn't let you get away with a lot of the sloppy programming habits that C and other languages do.  However, you probably can't find a compilor or books for it as it really doesn't have a pratical application anymore.  So my next choice would be C++, as it allows you to get under the hood of how things work.  You can directly manipulate memory, and while this frightens many people, it also allows you to directly see how it affects the program.

This is why I don't do much scripting anymore.  Too close to my work, which is what I want to get Away from in my time off.   :lol:


And now ladies and gentlemen comes the time where I relieve you of the burden of your failed and useless lives.  But if you gotta go, go with a smile!