|
You last visited: Today at 17:26
Advertisement
[Question] Coding Syntax
Discussion on [Question] Coding Syntax within the CO2 Programming forum part of the Conquer Online 2 category.
12/09/2010, 01:12
|
#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
|
|
|
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.
|
|
|
12/09/2010, 02:02
|
#3
|
elite*gold: 20
Join Date: Oct 2010
Posts: 451
Received Thanks: 259
|
Quote:
Originally Posted by pro4never
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.
|
|
|
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)
|
|
|
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.
|
|
|
12/09/2010, 03:47
|
#6
|
elite*gold: 20
Join Date: Oct 2010
Posts: 451
Received Thanks: 259
|
Quote:
Originally Posted by pro4never
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_
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
|
|
|
12/09/2010, 04:14
|
#7
|
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,885
|
Quote:
Originally Posted by FuriousFang
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_
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
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?).
|
|
|
12/09/2010, 06:28
|
#8
|
elite*gold: 0
Join Date: Feb 2006
Posts: 550
Received Thanks: 82
|
Quote:
Originally Posted by InfamousNoone
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() {
}
|
|
|
12/09/2010, 09:31
|
#9
|
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
|
Moved.
|
|
|
12/10/2010, 14:28
|
#10
|
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.
|
|
|
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).
|
|
|
12/12/2010, 01:32
|
#12
|
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.
|
|
|
12/12/2010, 09:05
|
#13
|
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,885
|
Quote:
Originally Posted by ChingChong23
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.
|
|
|
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!"; }
}
}
|
|
|
12/13/2010, 05:14
|
#15
|
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,885
|
Quote:
Originally Posted by Syst3m_W1z4rd
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!");
}
}
|
|
|
 |
|
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.
|
|