Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Assignment operator likes and dislikes  (Read 796 times)
0 Members and 1 Guest are viewing this topic.
Offline Varkas
« Posted 2013-01-14 14:48:50 »

If you are to use a scripting language, would you like this syntax for assigment and comaprison:

1  
2  
3  
            count := 0
            count := count + 1
            if count = 10 then


... or rather this one?

1  
2  
3  
            count = 0
            count = count + 1
            if count == 10 then


The first is based on Pascal, the second on Java/C syntax. I follow Mr. Wirth's argumentation to some point that an assignment is different from the mathematical equality "=" operator, and therefore should use something else. He suggested ":=" IIRC.

What do you think?

Edit: personally I'd prefer "count <- count + 1" to show the direction of the data flow.


if (error) throw new Brick(); // Blog (german): http://gedankenweber.wordpress.com
Offline orogamo
« Reply #1 - Posted 2013-01-14 15:09:02 »

If you want to "support" the major languages(for easier porting),
make your ifs, fors and whiles generic. Like C, C++, C#, Java etc
1  
2  
3  
if(this == that) {
...
}
Offline ReBirth
« Reply #2 - Posted 2013-01-14 15:15:24 »

I +1 for Java style == because it looks like emoticon.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online Roquen
« Reply #3 - Posted 2013-01-14 15:18:23 »

My first thought is:  don't design a scripting language.  Time sink, use an existing one unless you really want the learning exercise.
Offline Varkas
« Reply #4 - Posted 2013-01-14 15:19:46 »

If you want to "support" the major languages(for easier porting) [...]

The language in question is highly specialized and has a very tiny set of features. It's not a general purpose language, so porting other code to it will make no sense, I assume.

It'll be a language to create recursive graphical structures. To be more precise it will be an abstraction layer for this:

http://www.java-gaming.org/topics/greenspace-a-park-or-landscape-design-toy/27520/msg/258381/view.html#msg258381

I have most of it in place now, but before I release it, I want the syntax to be somewhat stable. Since C and Java are both in the top 3 of the programming language charts, I guess it's a good idea to stay close to their syntax, regrdless of the more theoretical considerations what would be a good syntax?

if (error) throw new Brick(); // Blog (german): http://gedankenweber.wordpress.com
Offline Varkas
« Reply #5 - Posted 2013-01-14 15:21:51 »

My first thought is:  don't design a scripting language.  Time sink, use an existing one unless you really want the learning exercise.

I had most of it already from older projects. It's done at the time of posting this, except better loops (hgas only goto now). The only question is the to decide on a syntax which the people like. And yes, I know that the standard approach is to use an existing language, and I full agree there.

if (error) throw new Brick(); // Blog (german): http://gedankenweber.wordpress.com
Offline jonjava
« Reply #6 - Posted 2013-01-14 15:29:05 »

:= is much more annoying to type than =.

Offline Varkas
« Reply #7 - Posted 2013-01-14 16:05:20 »

To give an idea what I have so far. A script like this ...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
// Turtle interpreter test
   
    setLineWidth(3)
    setScale(0.04)
    setColor(#FF7F00)
    startPainting()
    turn(180)
    up(10)
   
    count = 0
   
start:
   
    forward(40)
    placeSphere(1)
    turn(90)
    forward(40)
    placeSphere(1)
    turn(90)
    forward(40)
    placeSphere(1)
    turn(90)
    forward(40)
    placeSphere(1)
    up(5)
    turn(70)
   
    count = count + 1
   
    if count < 20
    {
        goto start
    }
    up(5)


... will create a graphic like this:



Since all suggestions were towards Java/C syntax, I've set up the interpreter this way currently. Color values are denoted #RRGGBB as in HTML. The script controls a "Turtle" ( http://en.wikipedia.org/wiki/Turtle_graphics ) which moves in 3D space and can draw lines (cylinders) there. Also place objects, spheres are used to round the bends in the example.

Maybe I should get rid of all the paranthesis around arguments?

if (error) throw new Brick(); // Blog (german): http://gedankenweber.wordpress.com
Offline sproingie

JGO Kernel


Medals: 202



« Reply #8 - Posted 2013-01-14 17:14:59 »

While I'm in favor of := for assignment, that battle was lost a long time ago.  Just use = for assignment and == for equality, and if your language distinguishes between statements and expressions, make assignment a statement.
Offline Pickleninja

JGO Coder


Medals: 10
Projects: 1


I'm tired of working for someone else.


« Reply #9 - Posted 2013-01-14 19:07:33 »

While I'm in favor of := for assignment, that battle was lost a long time ago.  Just use = for assignment and == for equality, and if your language distinguishes between statements and expressions, make assignment a statement.


Couldn't agree more.

Then again, the language you're most comfortable with will be the one you have a bias towards.


-Pickle

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (14 views)
2014-07-30 21:08:39

Riven (21 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (29 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!