Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Programming
You last visited: Today at 17:26

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Question] Coding Syntax

Discussion on [Question] Coding Syntax within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 20
Join Date: Oct 2010
Posts: 451
Received Thanks: 259
[Question] Coding Syntax

Hey everyone!
Is this good syntax?

Code:
#region Example
                if (Statement1 == 1)
                    if (Statement2 == 2)
                        switch (Statement3)
                        {
                            case 1:
                                if (Statement1 == Statement 2)
                                    Statement4++;
                                break;
                        }
                #endregion
Thanks!
Sincerely,
Fang
FuriousFang is offline  
Thanks
1 User
Old 12/09/2010, 01:16   #2
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,381
Umm... that would depend on what the statements are and why you would code anything that way?

in that you will never get statement4 to increase because you are requiring 1 and 2 to be different things and then checking for statement 3 to see if they are equal to modify statement 4.

Honestly what does this have to do with ANYTHING? :S....

Personally you should be doing a switch based on the type and then handle the other statements. As you have it right now, yes it will 'work' in that it will flow through properly but it will never actually execute anything.
pro4never is offline  
Old 12/09/2010, 02:02   #3
 
elite*gold: 20
Join Date: Oct 2010
Posts: 451
Received Thanks: 259
Quote:
Originally Posted by pro4never View Post
Umm... that would depend on what the statements are and why you would code anything that way?

in that you will never get statement4 to increase because you are requiring 1 and 2 to be different things and then checking for statement 3 to see if they are equal to modify statement 4.

Honestly what does this have to do with ANYTHING? :S....

Personally you should be doing a switch based on the type and then handle the other statements. As you have it right now, yes it will 'work' in that it will flow through properly but it will never actually execute anything.
I'm just using them as examples of what i'm trying to code.
I'm trying to code my own source and I want it to be as organized as possible with less brackets everywhere. All i'm asking is if it works without the brackets like that. The indentation looks like it will.
FuriousFang is offline  
Old 12/09/2010, 02:22   #4
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,381
Yah you don't need brackets to force indentation but keep in mind if statements only control the next line if you don't use brackets.

IE


if(Blah)
do action1
do action2

will only do action 1. To have it do both you'd need to surround them by brackets.

Switch statements are good any time you have more than a few things to discern between (IE: 3-4+ conditions I'd try to work it into a switch statement)
pro4never is offline  
Old 12/09/2010, 03:09   #5
 
elite*gold: 0
Join Date: Jun 2009
Posts: 787
Received Thanks: 314
It depends on how you want it really.
If you're developing by yourself just do it how you want it.

I prefer to put my { at the end of lines
Code:
int f(int x) {
    ....
}
but that's just me.
_tao4229_ is offline  
Old 12/09/2010, 03:47   #6
 
elite*gold: 20
Join Date: Oct 2010
Posts: 451
Received Thanks: 259
Quote:
Originally Posted by pro4never View Post
Yah you don't need brackets to force indentation but keep in mind if statements only control the next line if you don't use brackets.

IE


if(Blah)
do action1
do action2

will only do action 1. To have it do both you'd need to surround them by brackets.

Switch statements are good any time you have more than a few things to discern between (IE: 3-4+ conditions I'd try to work it into a switch statement)
I know that much =P
Thanks for confirming though!

Quote:
Originally Posted by _tao4229_ View Post
It depends on how you want it really.
If you're developing by yourself just do it how you want it.

I prefer to put my { at the end of lines
Code:
int f(int x) {
    ....
}
but that's just me.
That's how I code CSS! xP
FuriousFang is offline  
Old 12/09/2010, 04:14   #7
 
InfamousNoone's Avatar
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,885
Quote:
Originally Posted by FuriousFang View Post
Hey everyone!
Is this good syntax?

Code:
#region Example
                if (Statement1 == 1)
                    if (Statement2 == 2)
                        switch (Statement3)
                        {
                            case 1:
                                if (Statement1 == Statement 2)
                                    Statement4++;
                                break;
                        }
                #endregion
Thanks!
Sincerely,
Fang
In all honesty it's up to you. In my opinion: no.
I'd argue if your code was,
Code:
if (s == 1)
	if (s2 == 2)
		Method();
That's fine.
But, if you're going to need to open up a scope (breaking out the curly brackets), then I would surround every statement with curly braces, i.e.
Code:
if (s == 1)
{
	if (s2 == 2)
	{
		Method();
		Method2();
		Method3();
	}
}
verses;
Code:
if (s == 1)
	if (s2 == 2)
	{
		Method();
		Method2();
		Method3();
	}
Quote:
Originally Posted by _tao4229_ View Post
It depends on how you want it really.
If you're developing by yourself just do it how you want it.

I prefer to put my { at the end of lines
Code:
int f(int x) {
    ....
}
but that's just me.
Heard you like using lowercase method names, and instead of properties using getElement() and setElement(), bro'.

Quote:
Originally Posted by pro4never View Post
Yah you don't need brackets to force indentation but keep in mind if statements only control the next line if you don't use brackets.

IE


if(Blah)
do action1
do action2

will only do action 1. To have it do both you'd need to surround them by brackets.

Switch statements are good any time you have more than a few things to discern between (IE: 3-4+ conditions I'd try to work it into a switch statement)
Two things:
I don't know if you explained it because you think what he put in his code-quote wouldn't execute properly -- but to clarify, it'll run perfectly fine.

Secondly, using a switch-statement where it isn't necessary (as you said, under 3-4 cases) will be converted at compile-time to if-statements (assuming code optimizations is enabled -- but hey, why would you turn it off?).
InfamousNoone is offline  
Thanks
1 User
Old 12/09/2010, 06:28   #8
 
elite*gold: 0
Join Date: Feb 2006
Posts: 550
Received Thanks: 82
Quote:
Originally Posted by InfamousNoone View Post

Heard you like using lowercase method names, and instead of properties using getElement() and setElement(), bro'.

sounds like a java programmer, i also like

test() {

}
ChingChong23 is offline  
Old 12/09/2010, 09:31   #9


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
Moved.
Korvacs is offline  
Old 12/10/2010, 14:28   #10


 
KraHen's Avatar
 
elite*gold: 0
Join Date: Jul 2006
Posts: 2,216
Received Thanks: 794
I always put brackets after if statements, even if only one method comes after it, simply because I like it this way Oh and I never put the { like most Java programmers do, I find it irritating.
KraHen is offline  
Old 12/10/2010, 23:42   #11
 
elite*gold: 0
Join Date: Jan 2007
Posts: 656
Received Thanks: 541
I almost always use brackets no matter if it's for a switch statement or an if statement or almost any statement. For switch statements the reason you should use brackets is
1. It looks cleaner and more organized (In my eyes atleast).
2. If you wish to have 2 different variables, say a ushort and a double value with the same variable name (example y and y), then you must seperate the cases with brackets so that the variables are not conflicting within the same declaration space introduced by the switch statement.

For brackets with if statements, using brackets simplifies future work incase you have to add more within the if statement, and ontop of that it looks better and is more organized (atleast in my eyes).
Trigorio is offline  
Old 12/12/2010, 01:32   #12
 
Ian*'s Avatar
 
elite*gold: 0
Join Date: Nov 2006
Posts: 805
Received Thanks: 464
I think if your code does what you are trying to get it to do, and compiles successfully, AND IT DOESNT HURT YOUR EYES IT IS GOOD.

pic related:


QUIT DELETING ALL OF MY POSTS.

Ian* is offline  
Thanks
1 User
Old 12/12/2010, 09:05   #13
 
InfamousNoone's Avatar
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,885
Quote:
Originally Posted by ChingChong23 View Post
sounds like a java programmer, i also like

test() {

}
Saint (tao4229) and I despise Java, that's why I thought it'd be funny to post that. I'm glad other than us picked up on the joke.
InfamousNoone is offline  
Old 12/12/2010, 13:19   #14
 
elite*gold: 0
Join Date: Nov 2010
Posts: 1,162
Received Thanks: 370
Code:
    class Program
    {
        static int cookies;
        static void Main(string[] args) {
            int HowManyCookies = int.Parse(Console.ReadLine());
            Cookie(HowManyCookies);
            Console.WriteLine(Message(cookies)); }
        static int Cookie(int value) { cookies = value; return value; }
        static string Message(int Cookies) {
            if (Cookies > 0) {
                return "You have cookies!";
            }
            else { return "You have no cookies!"; }
        }
    }
Syst3m_W1z4rd is offline  
Old 12/13/2010, 05:14   #15
 
InfamousNoone's Avatar
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,885
Quote:
Originally Posted by Syst3m_W1z4rd View Post
Code:
    class Program
    {
        static int cookies;
        static void Main(string[] args) {
            int HowManyCookies = int.Parse(Console.ReadLine());
            Cookie(HowManyCookies);
            Console.WriteLine(Message(cookies)); }
        static int Cookie(int value) { cookies = value; return value; }
        static string Message(int Cookies) {
            if (Cookies > 0) {
                return "You have cookies!";
            }
            else { return "You have no cookies!"; }
        }
    }
Code:
    class Program
    {
        public static int Cookies { get; private set; }
        static void Main(string[] args)
        {
            Cookies = int.Parse(Console.ReadLine());
            Console.WriteLine(Cookies > 0 ? "You have cookies!" : "You have no coookies!");
        }
    }
InfamousNoone is offline  
Thanks
1 User
Reply


Similar Threads Similar Threads
Coding npc(last question)
06/17/2010 - CO2 Private Server - 20 Replies
hi, i have conquer pserver, i need a video who show me all the steps of changing the price of an npc( breeder for exemple) pelase guys, i know it's a lot but i'm so needding it thanks
[Question]Syntax for Pet..
03/22/2010 - EO PServer Hosting - 5 Replies
Hey, You know when you compose on top left it says " So and so have composed so and so." well something like that, Whats the Syntax for the pet? Like the Syntax %user_name = Display of the character name. I need to where i can find it and after 50* where the orange fireworks and the GM broadcast saying "So and so's pet is this many stars congratz" http://i430.photobucket.com/albums/qq23/MikeMadMa n_album/lol-1.jpg Just all smudgy cuz i wanna keep my privacy O_O Thanks.
Question About Coding...
07/03/2008 - Conquer Online 2 - 12 Replies
Ok I Need Sum Help With A PvP Server It Has infinity Stamina taths noth the probleem but HERC is (they spam it like hell ) How Could Our Team Delet Skill "Herc" or make the command admin Thx For Help If u Wanne Join Us go TO DragonCO :P



All times are GMT +1. The time now is 17:27.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.