Programing language

Brainstorm ideas of possible additions to the game. Read this before posting!

Moderator: Forum Moderators

Forum rules
Before posting a new idea, you must read the following:
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Programing language

Post by Sapient »

Viliam wrote: It needs an explanation about the meaning of "_", the difference between "description" and "user_description", and whether the values of "canrecruit" should be "yes"/"no" or "1"/"0" or "true"/"false", etc. But generally the meaning is obvious for non-programmer.
I would just like to point out that the keys "description" and "user_description" have already been corrected in the development version to "id" and "name" so they are easier to understand, and there is really no need to explain whether the values of "canrecruit" should be "yes"/"no" or "1"/"0" or "true"/"false", etc because all of those values are in fact allowed.

You can omit "_" if you don't care about translation, but I agree that it is confusing.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
uzytkownik
Posts: 126
Joined: April 19th, 2008, 7:12 pm
Contact:

Re: Programing language

Post by uzytkownik »

Viliam wrote:Changing the scripting language should probably be included into "frequently proposed ideas". ;-) A few times I proposed something like this too... or at least heavy changes into WML syntax so that macros will not be used so frequently.

But I like about your proposal that you actually wrote the scenario code in another language. If I remember correctly, nobody did this until now, so it was not even possible to discuss whether the code in another language would really be easier or not. Now at least the discussion based on real example is possible.
I've tried to search programming language on Ideas forum.
Viliam wrote:It surprised me that the Ruby code does not seem more legible, it is the opposite.
As I said - I have tendency to write short, legible-for-me code...
Viliam wrote:

Code: Select all

[side]
  side=1
  type=Dwarvish Fighter
  description=Burin
  user_description=_ "Burin the Lost"
  canrecruit=yes
[/side]
Maybe I probably chosed the part where the WML is strongest... describing a list of key-value pairs. But this code is very simple. It needs an explanation about the meaning of "_", the difference between "description" and "user_description", and whether the values of "canrecruit" should be "yes"/"no" or "1"/"0" or "true"/"false", etc. But generally the meaning is obvious for non-programmer.

Code: Select all

s.sides << Side.new(:human, :dwarves) do |side|
  side.leader = Unit.create_or_recall(side, :burin) do |burin|
    burin.id = :burin
    burin.type = UnitType.lookup("Dwarvish Fighter")
    burin.desc = _"Burin the Lost"
    burin.can_recruit = True
  end
end
This is just scary. Yes, it is a nice idea to use "<<" and "new" for adding a new side into a list of sides, but... this is just too complicated, and not really necessary. Thinking "side number 1" is easier concept than using dynamic arrays; and in 99% cases it does the work. Also I sometimes dislike WML for being too verbose, but in this Ruby example the "burin" keyword is really over-used.
Well - for me it easier to think about side called @player. s.sides I used only for the registration of sides. It was written fastly as near 1-1 rewrite.
Viliam wrote:I guess it could be done more effectively -- not sure how, I am not good in Ruby, but I guess just somehow writing key-value pairs should be enough, without repeating the object variable. Maybe. Instead of using things like "s.sides << Side.new(...)" and "UnitType.lookup(...)", it would be simpler to use methods, something like "side(...)" and "unittype(...)". The scenario object could be a subtype of "Scenario" class, and would inherit these methods.
The loading can be done automagically even. However I guess labels are more UF then need to access by number.
Viliam wrote:So the challenge (for all readers who love Ruby) is to make the Ruby code really simpler than the WML code. Do not try to make it more powerful than WML; just try to do the same thing somehow more simply. Use your programming skills for thinking about implementations of used functions, but keep the interface at least as simple as it is now.
Improved version. The example was written in 0.5h so it did not solved all API problems ;)
User avatar
Iris
Site Administrator
Posts: 6798
Joined: November 14th, 2006, 5:54 pm
Location: Chile
Contact:

Re: Programing language

Post by Iris »

Dave wrote:I think that Ruby/Python/Lua/whatever is always going to be intimidating for non-programmers.
They intimidate me already. (Perl doesn't.)

Also, most posts on this topic are not on the Ideas forum. They are either in WML Workshop or Coder's Corner, or moved to General Development to restrict discussion...
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
User avatar
loonycyborg
Windows Packager
Posts: 295
Joined: April 1st, 2008, 4:45 pm
Location: Russia/Moscow

Re: Programing language

Post by loonycyborg »

Dave wrote: I think that Ruby/Python/Lua/whatever is always going to be intimidating for non-programmers.
I think that you can design non-intimidating and clean interfaces with Python which don't require much dots, "<<"'s, "@"'s and other horrors.
"meh." - zookeeper
User avatar
Viliam
Translator
Posts: 1341
Joined: January 30th, 2004, 11:07 am
Location: Bratislava, Slovakia
Contact:

Re: Programing language

Post by Viliam »

Shadow Master wrote:
Dave wrote:I think that Ruby/Python/Lua/whatever is always going to be intimidating for non-programmers.
They intimidate me already. (Perl doesn't.)
I think the cause of intimidation is not because they are programming languages, but because the parts of code you see contain difficult concepts. And by "difficult" I mean "more difficult than your task really requires".

For example if you are trying to do something that requires variables, then the mere fact of using variables should not scare you. But if you are doing something that does not (in your opinion) need variables, and someone gives you a code that uses them, that is scary. Compare the following pieces of code:

Code: Select all

For x = 1 To 10
  WriteLine x
Next x

Code: Select all

for (int x = 0; x < 10; x++) {
  write_line(1 + x);
}
Both do the same thing... write numbers from 1 to 10, one per line. The first example does not add many new concepts beyond "repeating" and "number of repetition", which are required by the task. But the other example has a lot of scary things. Why do I have to learn that "++" is a symbol of increasing by 1? Are there many such mystical symbols? Something like "+1" or "increase" or "next" would be easier to read. What is "int"? Why start repeating at "0"? (I know that was not necessary; but I guess this is how many C/C++ programmers would write it.) Etc.

For programmer, both pieces of code do the same thing. But for non-programmer the second example contains many new parts that need to be explained and understood. Memorizing "For ... = ... To ... Next" is similar to memorizing "for(...;...;...) {...}", but after you have memorized the first one, you are able to write the code, while after memorizing the second one, you also have to remember that first parameter is type declaration and initialization, second parameter is condition, third parameter is the end of loop. What?! All I wanted to do was to display numbers from 1 to 10, why do I have to learn such difficult concepts?

The point is not comparing languages, but rather the way they are used (although some languages will not give you too much choice). For example here are two (not necessarily syntactically correct) examples in Perl. They could do the same thing. Yet the first one is IMHO not intimidating, but the second one surely is.

Code: Select all

$side1 = {
  "name"   => "dwarves",
  "leader" => {
    "type"       => "Dwarvish Fighter",
    "id"         => "Burin",
    "name"       => _"Burin the Lost",
    "canrecruit" => YES
  }
};

Code: Select all

my $side1 = Wesnoth::Model::Side->new();
$side1->setName("dwarves");
my $leader1 = Wesnoth::Model::UnitInstance->new(
 Wesnoth::Model::UnitType->getFactory()->getUnitTypeByName("Dwarvish Fighter"));
$leader1->setId("Burin");
$leader1->setName(Wesnoth::Localization->translate($textdomain, "Burin the Lost"));
$leader1->setCanRecruit(1);
$side1->setLeader($leader1);
push(@sides, $side1);
The second example is exaggerated, to make the point more obvious.
User avatar
Gambit
Loose Screw
Posts: 3266
Joined: August 13th, 2008, 3:00 pm
Location: Dynamica
Contact:

Re: Programing language

Post by Gambit »

i have only one thing to say.

a huge part of the reason i downloaded wesnoth was the advertisement of "FULLY MODIFYABLE!" "very easy to make new things"


im sure im not alone in that. the basic game itself does get dry after a while. theres new UMC like every day. i am a programmer. VB C++ and i do some web designing as well (By hand in notepad, not that dreamweaver crap). And I must say WHY THE HECK WOULD YOU WANNA GO BACK TO THAT? WML IS SO EASY!

and as for your "reinventing the wheel and not even doing it right" bulldung. go open up wesnoth. click addons. sort by name. scroll down to bob the mighty. download everything by him. play it all.

AND THEN TELL ME YOU CANT DO ANYTHING AWSOME WITH WML (without lying :P )

you cant say it honestly. and then download all the other addons and play all of them. they're so diverse. nothing is "reinvented" (except maybe art :P ).

you sir are just to lazy to put in the time writing out WML to make something. if you really want to do something incredible, then you have to put in some time. even if it takes you your entire summer vacation. if i may quote Eldest here

"its like making lace. it isnt strenous. it just takes some time."-Nasuyda


mods im sorry for the flaming but this touched a cord :(
Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

Re: Programing language

Post by Dave »

loonycyborg wrote: I think that you can design non-intimidating and clean interfaces with Python which don't require much dots, "<<"'s, "@"'s and other horrors.
I don't think it's just the syntax that's confusing; it's the concepts. I am very doubtful a Python interface could end up as easy for a non-programmer as WML is.
Gambit wrote: mods im sorry for the flaming but this touched a cord :(
Not at all; thank you for pointing things out from a campaign developer's perspective.

David
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
User avatar
loonycyborg
Windows Packager
Posts: 295
Joined: April 1st, 2008, 4:45 pm
Location: Russia/Moscow

Re: Programing language

Post by loonycyborg »

Dave wrote:
loonycyborg wrote: I think that you can design non-intimidating and clean interfaces with Python which don't require much dots, "<<"'s, "@"'s and other horrors.
I don't think it's just the syntax that's confusing; it's the concepts. I am very doubtful a Python interface could end up as easy for a non-programmer as WML is.
I don't see any concepts in python that are inherently harder to grasp than ones in WML. Besides, a well designed interface will use only those concepts that map neatly to problem domain. You can make interface that will make programs using it look almost like WML :)

Code: Select all

side1 = Side(
  name = "dwarves",
  leader = Leader(
    type = "Dwarvish Fighter",
    id = "Burin",
    name = "Burin the Lost",
    canrecruit = True
  )
)
"meh." - zookeeper
Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

Re: Programing language

Post by Dave »

loonycyborg wrote: I don't see any concepts in python that are inherently harder to grasp than ones in WML.
I think plenty of people would disagree with you fairly strongly on that. :)
loonycyborg wrote: Besides, a well designed interface will use only those concepts that map neatly to problem domain. You can make interface that will make programs using it look almost like WML :)
But this will put the user in a little sandbox inside Python which is just a clone of WML anyhow. Any stepping outside this sandbox and they will be in a complex programming language.

Additionally, several very useful WML features won't be possible, such as [+append] and x,y=4,8 style syntax.

It'd also be a lot less convenient than WML unless you plan to add a pre-processor on top of Python as well.

Also after reading this data in, I don't think it'd be possible to serialize back to the same format (correct me if I'm wrong on that).

I'm not sure about error messages, but I'd imagine they might end up harder to read with Python.

David
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
uzytkownik
Posts: 126
Joined: April 19th, 2008, 7:12 pm
Contact:

Re: Programing language

Post by uzytkownik »

Gambit wrote:i have only one thing to say.

a huge part of the reason i downloaded wesnoth was the advertisement of "FULLY MODIFYABLE!" "very easy to make new things"


im sure im not alone in that. the basic game itself does get dry after a while. theres new UMC like every day. i am a programmer. VB C++ and i do some web designing as well (By hand in notepad, not that dreamweaver crap). And I must say WHY THE HECK WOULD YOU WANNA GO BACK TO THAT? WML IS SO EASY!
Well - what is more easy:

Code: Select all

if($var1 == 1 || $var2 == 2) {
  ...
}

Code: Select all

[if]
  [variable]
    name=var1
    equals=1
  [/variable]
  [or]
    [variable]
      name=var2
      equals=2
    [/variable]
  [/or]
  [then]
    ...
  [/then]
[/if]
To begin with - very strange for me is the or construct.
Lack of else if is also rather painful in some contexts.

PS. I do not propose C++ as language. I did propose some scriptiong language.
Gambit wrote:
and as for your "reinventing the wheel and not even doing it right" bulldung. go open up wesnoth. click addons. sort by name. scroll down to bob the mighty. download everything by him. play it all.

AND THEN TELL ME YOU CANT DO ANYTHING AWSOME WITH WML (without lying :P )
As WML is turing-complete AFAIK you can write any algorithm in it. You can write a compilator in WML.

So are assemblers. You can do awsom things in assembler - but they are not easy. You can do awsom thing in Wesnoth. But it tends to be neighter easy nor intuitive if you want to do something unusual.

Of course - WML is much simpler then assembler - but I guess they you have seen my point. Long time ago everything was programmed in assembler. In fact you can do anything in assembler. But it does not make assembler an easy language to program with. There is no implication.
Gambit wrote:you cant say it honestly. and then download all the other addons and play all of them. they're so diverse. nothing is "reinvented" (except maybe art :P ).
You miss my point. The reinvention was about WML as language - not addons.
Gambit wrote:you sir are just to lazy to put in the time writing out WML to make something. if you really want to do something incredible, then you have to put in some time. even if it takes you your entire summer vacation. if i may quote Eldest here
Thanks. But you see - I don't consider myself lazy as concerning to programming languages. I'm currently maintain activly one project in Ruby, one in C.I've also do a bit of programming in Perl, C++, Haskell, C#, Python, shell, x86 assembler (both Intel and AT&T syntax)[1] and several others. So I KNOW what I'm talking about that the WML takes me much more time and pain then others - especially from it's level(scripting languages).

So please anything (I may be dumb etc.) but not that I'm lazy in concern to programming languages "just too lazy to put in the time". May be I'm not fluent in them but I know several of them.

[1] There was usually small projects just to recognize the features of language. However I guess that they had similar or bigger complexity than what I want to achive in WML.
mods im sorry for the flaming but this touched a cord :(
Please - DO NOT MAKE PERSONAL ATTACKS. I could say that knowing 2-3 languages do not make you a programmer - in similar way I was accused of being lazy. I don't know neighter your level[1] neither what you can consider 'knowing the language'[2].

[1] Could be anything from hello-world level to top-high-paid consultant
[2] Similar can be from hello-world to professional level
ivan
Posts: 15
Joined: April 28th, 2008, 12:42 pm

Re: Programing language

Post by ivan »

loonycyborg wrote:
Dave wrote: I think that Ruby/Python/Lua/whatever is always going to be intimidating for non-programmers.
I think that you can design non-intimidating and clean interfaces with Python which don't require much dots, "<<"'s, "@"'s and other horrors.
Completely agree.

Here's my version:

Code: Select all

from factions import dwarf
from wesnoth.campaign import Side, Leader

burin = Leader(type=dwarf.fighter, name='Burin the Lost', canrecruit=True)
dwarves = Side(leader=burin)
Some ids and names could be dropped, because Python objects themselves can do the job.

In Python you can reuse and modify existing objects and keep everything organized. Anything non-trivial in WML becomes a mess.

The main problem I see is that it will require almost complete rewrite of Wesnoth, and this is a real problem.
User avatar
loonycyborg
Windows Packager
Posts: 295
Joined: April 1st, 2008, 4:45 pm
Location: Russia/Moscow

Re: Programing language

Post by loonycyborg »

Dave wrote: But this will put the user in a little sandbox inside Python which is just a clone of WML anyhow. Any stepping outside this sandbox and they will be in a complex programming language.
WML itself isn't omnipotent either. But there's no complex programming language to resort to if needed.
Additionally, several very useful WML features won't be possible, such as [+append] and x,y=4,8 style syntax.
I still don't know much about WML and can't say whether there's a way to provide something equivalent or better with python.
It'd also be a lot less convenient than WML unless you plan to add a pre-processor on top of Python as well.
I don't see how WML preprocessor is more convenient than defs or classes in python.
Also after reading this data in, I don't think it'd be possible to serialize back to the same format (correct me if I'm wrong on that).
There are ways to serialize python code objects.
"meh." - zookeeper
ivan
Posts: 15
Joined: April 28th, 2008, 12:42 pm

Re: Programing language

Post by ivan »

Dave wrote:
loonycyborg wrote: I don't see any concepts in python that are inherently harder to grasp than ones in WML.
I think plenty of people would disagree with you fairly strongly on that. :)
And plenty of people would strongly agree :)
Dave wrote: Additionally, several very useful WML features won't be possible, such as [+append] and x,y=4,8 style syntax.
x,y=4,8 is perfectly valid Python syntax. I don't know what [+append] means, but I'm sure something similar can be implemented in Python.
Dave wrote: It'd also be a lot less convenient than WML unless you plan to add a pre-processor on top of Python as well.
Python functions and objects are powerful enough to be more useful than any WML pre-processors.
Dave wrote: Also after reading this data in, I don't think it'd be possible to serialize back to the same format (correct me if I'm wrong on that).
Agreed. WML is far superior for some data than scripting languages. Even if Python (or Lua/Ruby) will be used to script scenarios and campaigns, WML should stay for maps and UIs.
uzytkownik
Posts: 126
Joined: April 19th, 2008, 7:12 pm
Contact:

Re: Programing language

Post by uzytkownik »

ivan wrote:
Dave wrote: Additionally, several very useful WML features won't be possible, such as [+append] and x,y=4,8 style syntax.
x,y=4,8 is perfectly valid Python syntax. I don't know what [+append] means, but I'm sure something similar can be implemented in Python.
Add the code to last node of this type. The only use I find for it as far is:

Code: Select all

{SOME_MACRO}
[+something]
  customize_the_macro_content
[/something]
ivan
Posts: 15
Joined: April 28th, 2008, 12:42 pm

Re: Programing language

Post by ivan »

uzytkownik wrote:
ivan wrote: x,y=4,8 is perfectly valid Python syntax. I don't know what [+append] means, but I'm sure something similar can be implemented in Python.
Add the code to last node of this type. The only use I find for it as far is:

Code: Select all

{SOME_MACRO}
[+something]
  customize_the_macro_content
[/something]
Every dynamic language can do it. You can change and add anything to any object any time.
Post Reply