ID:102637
 
The DM language lacks a lot of features that make it easy to maintain large projects. The language doesn't make it easy for features like code completion to be implemented. For this and several other reasons the programmer has to remember more than they would if they were using a different language.

For example, in Java you don't need to remember whether the method to add an object to an ArrayList is called "add" or "insert" because your IDE can tell you what methods an ArrayList object has. Here's an example from Eclipse:



You can see that it's called "add". If you weren't sure if the method to return the number of items was "size" or "length" you can easily find that out too. In DM projects you can't do this. To know the types of arguments and the type of return value for a given proc you need to either have them memorized or dig through code to find it out. When you come back to a DM project after a while it takes time to get used to working on it again because you don't have this information memorized anymore.


The Idea

This gave me an idea: Create a program that converts Java code to DM and provide a Java project that defines BYOND's built-in vars and procs. You get the benefits of using a Java IDE (code completion) and Java's features (type safety). For example:

public class mob
{
public void Login()
{
loc = locate(3,4,5);
}
}


Would be converted to:

mob
Login()
loc = locate(3,4,5)


This is not a proper translator. The goal is not to convert a working Java program to a working DM program. The purpose is to leverage Java's strong typing and feature-rich IDEs. The development would be done entirely in Java, you'd only convert the code to DM to execute it.

In the example above you'd see this:



You would also get argument lists and return types for functions that you've defined.

The Java code would compile but not execute. To execute the code you'd need to convert the Java code to DM code then compile that (this process would be automated). You can use Java's compile-time errors to check for potential problems in your code. For example:

// Java
mob m = get_dist(a,b)
System.out.println(m.name);

// DM equivalent
var/mob/m = get_dist(a,b)
world << m.name


The DM compiler won't complain about that code but it will have a runtime error. The Java compiler would catch this because it knows that get_dist returns an integer, not a mob.


Problems

The biggest problems occur where Java's syntax differs from DM's. These issues are major when the feature is necessary. For example, Java has no global variables or methods but these are necessary in DM (if for nothing else than to reference the built-in global procs). Having no global variables or methods means that to access the locate proc like I did in these examples, the locate proc would need to be a member of the datum class. I'm not sure if there's a way to have a class contain all global vars/procs and be able to reference it without an identifier (global.locate(x,y,z) is not ideal).

Type safety might be an issue for some parts of DM that aren't well defined themselves. DM doesn't have much of a concept of an "overlay" object but we'd need to establish one. This seems possible but there might be some issues hidden in there.

Some DM tricks that use ..() might not be doable. This isn't a huge problem because there's a way to write equivalent code without using ..() but DM users might be used to it.
Don't know about previous Visual C++, but the newer 2010 has the same features that DM lacks.
Ideally a language that's similar to DM would be used. I'm not sure if Java or c++ is more similar.
I don't think DM really intends to compete with Java. It's remarkably advanced for what it's intended to do: allow people to quickly bring up their online homebrew games and prototypes. I wouldn't hold it against anyone who has mastered DM to move onto Java (although they'll likely need a game library, such as JAGEX, to get a lot of the functionality DM has built in).
The purpose is not to say that Java is better, but to show how DM games could be developed using Java so that you can still use BYOND but get the benefits of using Java too. You write code in Java and run a program to convert it to DM code.

For example:

mob/proc/get_target()
for(var/mob/m in oview(5,src))
return m


You have a get_target proc that finds a target (a mob) and returns it. This is fine, but later on you want to change the proc so that it returns some additional information. You create a simple data structure to hold all of this information:

TargetInfo
var
mob/mob
info
New(mob/m, i)
mob = m
info = i

mob/proc/get_target()
for(var/mob/m in oview(5,src))
// gather some additional information
return new /TargetInfo(m, info)


When you make this change, all code that referenced get_target will break because it's expecting a mob, not a TargetInfo object.

If you're writing code in Java that will be converted to this DM code, when you compile the Java program you'll get errors on each line that calls get_target. Here's the Java code:

class mob
{
public mob get_target()
{
for(mob m: oview(5,this))
{
return m;
}
return null;
}
}

// And this is the DM code it would be converted to:
mob
proc
get_target()
for(var/mob/m in oview(5,src))
return m
return null


Because you have return types in Java when you change it to TargetInfo the Java compiler will tell you where errors are.

This is also helpful if you stop working on this project and come back a month later. You might have forgotten that the get_target proc returns a TargetInfo object instead of a mob but the IDE can give you a list of methods and their return types.
I would say that Java is more similar to DM than C++ is, though that really isn't saying much...


A problem with this is that in order for the IDE to fill in details like this (and I love this feature in C++ and Java IDEs), variables in DM need to be more strictly typed.

A variable in DM is just var, and it can store any kind of value. There's nothing for the compiler to really be able to tell the difference between a number (single precision float), string, or even an object (since you can do
var/M = new/atom()
however ugly that may be)

You can't really do that in Java; you need either the primitive type or an object type to assign to the identifier.

When the variable in DM is typecasted though, like var/mob/M, it would be convenient for the IDE to be able to provide the menu for attribute or function name fill-ins. I don't think that any change to the syntax is needed for this.


Something else I'm kind of sad about is that you can't do
"array[index].function();" 
or
"object.name().substring();"
in DM, whereas you can do it in Java. I guess it's a pretty minor point but it's also another thing towards convenience.


Converting Java code to DM... I guess that could be nice.
If it's your own code, you should understand it well enough to be able to convert it by hand anyway...
Who are you... and don't you lie to me.. >.>
The conversion is one way, Java to DM. For example:

// Java code
int x = 3;
double y = 3.4;
String s = "hello, world!";

// Resulting DM code
var/x = 3
var/y = 3.4
var/s = "hello, world!"


We don't need to worry about using a var/mob/ to store a reference to an atom or a number. We only need to find DM equivalents for what you can do in Java, not Java equivalents of what you can do in DM.

Things like "array[index].function();" would cause errors because there's not really a DM equivalent. This would cause an error in the automated conversion step.

If it's your own code, you should understand it well enough to be able to convert it by hand anyway...

The point is to create an automated conversion process so that only the Java code is edited. You don't even need to see the DM code, it's just used as an intermediate step to generate the .dmb. The purpose of the conversion is to let the developer leverage the benefits of Java while still developing a BYOND game - this could also be an "easy" way for BYOND to get support for frequently requested features (like code completion).
Dream Maker Pro.... O.O....

Basicly, no more going to the Help-On section because you forgot if that proc is Get_Pixel() or GetPixel()! Fancy stuff.
It's an interesting idea but you have to remember DM, although not supported by a powerful IDE such as Eclipse, is much easier to use than Java (especially when it's Java converted to DM!). Writing even slightly complex code in Java makes you appreciate how much DM already does for you. I'm not sure the tradeoff is worth it.
Toadfish wrote:
Writing even slightly complex code in Java makes you appreciate how much DM already does for you. I'm not sure the tradeoff is worth it.

I'm not sure what you mean, can you provide an example?

The beauty of this is that the Java code doesn't need to work.

This project would have two parts: a Java to DM converter and a skeleton Java project. The skeleton would provide stubs for methods so you could do things like this:

// Java code
for(mob m: view(5,this))
{
m.health = m.max_health;
}

// and it would be converted to
for(var/mob/m in view(5,src))
m.health = m.max_health


The skeleton Java project would define a view method but it wouldn't need to function, it only needs to compile.
I am talking about the many minor things DM already does for you. Providing an example would make my argument weaker than I think it is, as I'm not talking about a particular 'major' issue but rather the little things that pile up. However, for example, DM doesn't require you to specify what type of information a variable holds, and all variables can refer to all types (Edit: from your post, it looks like you prefer strong typing :p). A different issue (that you already addressed) is the things you can do with ..(). These are not major issues, but they pile up, and you end up writing a source code that's very different not only in syntax, but in structure, from what a DM equivalent would normally look like. In other words, you can't write "natural" code in "Java-DM".

I'm still not entirely sure my concerns are justified, but I believe they are. The best way to test this would be to take a (moderate) project and convert it to Java-DM, to see what problems arise.
It probably be easier to just write your own DM IDE than to waste time trying to get it to work with Java, besides if you forget how something works in DM or aren't sure of the name, F1 next to things brings up the reference and usually looks up the word before the cursor for you.
Sinfall, I think the charm of this is that it's actually a pretty simple thing to do (at least when compared to an actual IDE for DM).
if you forget how something works in DM or aren't sure of the name, F1 next to things brings up the reference and usually looks up the word before the cursor for you.

This doesn't help when you forget how code that you wrote works.

Also it would be very difficult to implement code completion in a DM IDE because there is no strong typing.

In other words, you can't write "natural" code in "Java-DM".

This is a concern. Another problem I was going to mention was handling lists:

// Java code
ArrayList<String> L = new ArrayList<String>();
L.add("hello, world!");

// DM equivalent
var/list/L = list()
L += "hello, world!"


There's quite a difference in syntax. C++ might be a better option because operator overloading might allow for a syntax that's closer to DM. Edit: C++ has its quirks, but would also allow for code to be split up differently. Having all mob code in mob.java is not ideal, especially because there is some built-in stuff that you wouldn't want to modify.

Edit #2:
from your post, it looks like you prefer strong typing

I certainly do. I suspect the lack of strong typing (and the benefits that come with it) is why many BYOND games are developed in a frenzy: people work on them a lot for a few days then typically never touch them again. Once you take long enough of a break that you forgot the intricate details of how the code worked it's such a hassle to work on the project and the IDE can't help you.
I certainly do. I suspect the lack of strong typing (and the benefits that come with it) is why many BYOND games are developed in a frenzy: people work on them a lot for a few days then typically never touch them again. Once you take long enough of a break that you forgot the intricate details of how the code worked it's such a hassle to work on the project and the IDE can't help you.

I hadn't thought about this before. Even putting strong typing aside, DM allows a lot of liberty when writing code, and perhaps encourages it. I'd say that BYOND as a whole encourages "development frenzy" as part of its nature. Taking this into consideration makes having a good IDE all the more important.
Think of all the things you need to remember about a DM project: icons, icon_states, animation durations, variables, procs, proc arguments, return values, object type paths, control names, window names, tags, z-levels, macros, and screen_locs. I'm sure there are more that I missed.

Part of the reason the developer has to remember these things is because DM is dumping work on you to keep things simple. Having to define a type for a proc's return value is a hassle and could make code confusing to beginners. Not defining return types keeps code simple but in the end the developer is losing out because it's just another thing they have to memorize.

If BYOND had features to reduce the developer's memory load I'm absolutely certain you'd see better BYOND games. Maybe I'll polish up my DM wish list and post that soon.
Not only is this easier than it sounds, it also solves problems that a better DM IDE couldn't. No DM editor could tell you what a proc's return type is because you don't specify types for return values in DM.
I was under the impression that you were building an IDE for DM.
Page: 1 2