ID:987319
 
turf
{
environment
{
icon='Environment.dmi'

Cactus
{
icon_state = "cactus1"
density=1
}
Grass
{
icon_state = "grass"
}
Grass2
{
icon_state = "grass2"
}
Grass3
{
icon_state = "grass3"
}
Grass4
{
icon_state = "grass4"
}
}
}


What's certainly wrong with using braces in the DM language. I mean, some people said it makes debugging stuff easier, others just said; "why in the hell would you use braces on dm".

I never used them myself, but I already saw a few people using it, and I am just wondering if it makes any difference, either in debugging or game's performance at all.
It makes no difference, it's just a personal choice. Some people are just used to using braces in other languages. It has no effect on the code once it's compiled.
Looking at it like makes easier to find important stuff, I guess I will try using it. If it has no impact once compiled, then am safe.

Interesting though.
I don't see how it makes anything easier to find. You could just as easily (or more easily) put a blank line where the braces are in your example, and have the code be just as readable.
You can use that to compress code too;
        
turf{environment{icon='Environment.dmi';Cactus{icon_state = "cactus1";density=1;}Grass{icon_state = "grass";}Grass2{icon_state = "grass2";}Grass3{icon_state = "grass3";}Grass4{icon_state = "grass4";}}}
Yeah, that would make more sense in the use of braces.
Nice example.
I usually use braces just for if statements, and other processes through the code.
Here are some more tips you can use without explaining compiler theory to you,

mob/proc/whatever()
if(!src) return
var/a=5,b=6
world<<a+b


If you want if statements to execute more than 1 line of code in this format, you need to use a semicolon
mob/proc/whatever()
if(!src) world<<"no";return
var/a=5,b=6
world<<a+b
I also used it this way:
/proc/passretrieve()
var{p1="My";p2="Password!"}
return md5(p1+p2)
Suicide Shifter wrote:
mob/proc/whatever()
if(!src) world<<"no";return
var/a=5,b=6
world<<a+b


mob/proc/whatever()
if(!src) { world << "no"; return }
var a = 5, b = 6
world << a + b


Statements like if/else, for, while, etc. take a statement or a code block. One statement. Or a code block.
// this is one statement
if(1) return

// this is two statements!
if(1) a(); return

// it's read like this
if(1)
a()
return // notice how it's ignored by the if().

// this is like one statement;
// it's a block that contains two!
if(1) { a(); return }

Curly braces transform multiple statements into a code block, which could be thought of as the if() treating it as one statement. In DM, the newline and tab creates a block.
In response to Kaiochao
This. What was I thinking...?
It's used in PHP, it's just personal preference on BYOND, things can get messy if you don't know what you are doing.

You can also use them for multi lined vars.

var/html = {"
<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>

<p>My first paragraph.</p>

</body>
</html>
"}
Lol I knew all those methods of usage for them.
I was just wondering how good or bad using it in definitions, as in the example I gave, effect the game itself, programming-wise.

As DC said, It makes no difference so the topic was solved a while ago o.o

But this will help others who may be interested in the use of braces, so, well said.
In response to Neo Rapes Everything
Neo Rapes Everything wrote:
As DC said, It makes no difference so the topic was solved a while ago o.o

This post isn't that old not even 24 hours by my count, so it's not a huge issue that I posted my comments on a forum that used for conversing.

Last Post - "Yesterday, 11:45 pm" - it's today Tues 25th September (the future for some Americans) the next day from yesterday and it's 2:09PM.

But this will help others who may be interested in the use of braces, so, well said.

Yes indeed.
I use other programming languages(e.x., Java, C, C++) daily and personally, curly braces are annoying. I don't see the extra benefit of them in DM, either. In my eyes it just makes your code even more sophisticated to organize; not to mention it's another needless keystroke.
DM does us a favor by essentially replacing curly braces with tabs...I think? When programming in C, tabs are ignored by the compiler, so if you were insane you could write every line of code starting at the very left margin. What DM does is treat consecutive lines of code that are at the same margin as if they were enclosed in braces.

I suggest not using them unless you are so accustomed to a different language that your fingers type them without you thinking about it :D
.___. when coding in C# I still need to use indents...

Anyway, braces just make the code easier to read (for DM at least.) If you plan on passing your code onto another generation of coders then it's probably best if you use braces so it's easier for new people to read. If it's for personal use you can do whatever you want and still get the same result.
In response to The Monster Atlas
I disagree wholeheartedly. I think braces just look messy, are non-standard (for BYOND), and should not be used when sharing code with others--especially for those who are new to programming in general. The mere existence of this thread shows that some new users are being confused by them.

I'll take Show Tabs over braces any day.
If those who are new to programming don't understand what a brace is, they are not learning properly. Braces are the foundation of current language because their predecessors used them. Though newer languages aren't including them, it's nice to have closures like semi-colons and dividers like braces in order to read code easier.

But that being said, DM is one of the easiest languages to read.
If you're not learning how to use 'begin' and 'end' then you're not learning correctly!

Seriously though...just because curly braces are used a lot, doesn't mean they are the foundation of current language. There are plenty of other languages, some older than C, that do not use braces and semicolons.

Also:
"nice to have semi-colons and braces in order to read code easier."

"DM is one of the easiest languages to read."

What?
In response to The Monster Atlas
The Monster Atlas wrote:
If those who are new to programming don't understand what a brace is, they are not learning properly. Braces are the foundation of current language because their predecessors used them. Though newer languages aren't including them, it's nice to have closures like semi-colons and dividers like braces in order to read code easier.

But that being said, DM is one of the easiest languages to read.

Monster Atlas please research Python. Braces are not the foundation and I do not believe there's any reason why Byond requires brace functionality except for inline statements.
Page: 1 2