(编程)各种语法样式 [英] (Programming) Various Syntax styles

查看:66
本文介绍了(编程)各种语法样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数(如果不是全部)

编程语言都有大量的语法风格。


例如,一种语法风格(我当前一):


....

int main()

{

for( int i = 0; i <50; i ++)

{

cout<< Hello World!\ n;

j = 2 * i + 1; //一些奇怪的计算

}


返回0;

}


但我正在考虑改变,改变一种在

编程语言中使用得更广泛的风格。如果我似乎不喜欢它,我将返回我的

当前的一个...新的风格是:


int main(){

for(int i = 0; i< 50; i ++){

cout<< Hello World!\ n;;

j:= 2 * i + 1;

}


返回0;

}


我现在似乎没有真正习惯它(因为它只是开始)。

我想要改变,因为在很多地方我看到了第二个

风格,所以我认为它更好(看起来)。


什么是你的有利的SYTLE ??????????????举例说明是否需要


解决方案



" Chris Mantoulidis" <厘米**** @ yahoo.com>在消息中写道

新闻:a8 ************************** @ posting.google.c om ...

大多数(如果不是全部)编程语言都有大量的语法样式。

例如,一种语法样式(我当前的样式):

...
int main()
{
for(int i = 0; i< 50; i ++)
{
cout<< Hello World!\ n;
j = 2 * i + 1; file://一些奇怪的计算


返回0;
}

但我正在考虑改变,改变风格更多广泛用于编程语言。如果我似乎不喜欢它,我会回到我当前的那个......新的风格是:

int main(){
for(int i = 0 ; i< 50; i ++){
cout<< Hello World!\ n;;
j:= 2 * i + 1;
}

返回0;
}
我想改变因为在很多地方我看到了第二种风格,所以我想它(看起来更好)。

你最喜欢的是什么??????????????????????????????????????????????????????????举例说明是否需要




没有最好的编码风格。你选择哪种编码风格并不重要,只要它是一致的。如果您使用与周围其他人相同的

编码样式,它也会有所帮助。在我工作过的所有地方中,首先是首选的编码风格。因为我已经习惯了这种风格,所以格式化的代码格式比第二种风格更容易为我阅读。我希望

对于习惯于第二种风格的人来说是另一种方式。


如果你独自工作,选择你最喜欢的东西。如果你在一个小组中工作,那么使用其他人使用的编码风格

。除此之外,我认为没有理由支持
开关样式。


-

Peter van Merkerk

peter.van.merkerk(at)dse.nl


On Thu,2003年12月11日06:17:18 -0800,Chris Mantoulidis写道:

我现在似乎没有真正习惯它(因为它只是开始)。
我想改变因为在很多地方我看到了第二个
风格,所以我认为它更好(看起来)。




单独工作时使用你喜欢的风格。当你在一个小组中工作时使用共同的风格。


至少在一个源文件中保持一致。


缩进的标签是邪恶的,但不像混合标签和空格那样邪恶。


-

NPV


大字印刷品,小字印刷品

Tom Waits - 向上走吧


Chris Mantoulidis写道:

大多数(如果不是全部)
编程语言都有大量的语法样式。

例如,一种语法风格(我当前的一种):

...
int main()
{
for(int i = 0; i< 50; i ++ )
{
cout<< Hello World!\ n;
j = 2 * i + 1; //一些奇怪的计算


返回0;
}




用你的例子我有趣的编码风格是:


int main(){for(int i = 0; i< 50; i ++){cout<<"" Hello World!\ n" ;; j = 2 * i + 1;

//一些奇怪的计算

}返回0;}


它是通过以下方式获得的C程序:


/ ************************文件:cz.c ***** *****************

已经证明C或C ++程序中的错误数量

是成比例的到源文件的行数。

这个程序戏剧性地减少了错误的数量,减少(最多99%)源中的行数。

显然是由这个程序运行的源代码:

语义等同于原始的

但它的可读性较差!

尝试所有表格:

cz cz.c cz_short.c

cz -256 cz.c cz_small.c

cz -30000 -X cz.c cz_atom.c

cz -0 cz.c cz_long.c

获得:

cz_short.c(200行长)

cz_small.c(118行长)

cz_atom.c(27行长)

cz_long。 c(2746行)

来自:
cz.c(639行)

作者:Dario电子邮件: da *** @ despammed.com

****************** ******************************** ********** // *

版本历史:

1.0 Dec 6 1994

初始版

1.1 Dec 7 1994

1。正确来自:
sscanf(argv [i] +1,"%ld"& maxOutLen)

to:

sscanf( argv [i] +1,"%d"& maxOutLen)

2.更正来自:
static char * operator [] = {...

到:

静态字符* operatorString [] = {...

3.运算符添加到operatorString:

%%%% ...<> < %%> < ;::> %%

4.介绍函数isIdientifierLetter

5.更改自:
* n = * n + 1;

to:

(* n)++;

6.更正来自

#if定义(__ STDC__)||定义(__ cpluscplus)

到:

#if定义(__ STDC__)||定义(__ cplusplus)

7.内存分配器的结果添加了许多强制转换

8.正确来自:
static forceNewLine(void)< br $>
to:

static void forceNewLine(void)

1.2 Dec 12 1994

1.认可为预处理行a以%%开头的行

2.现在也可能由前ANSI-C编译器编译

1.3 Aug 04 1997

1.第三strncmp的参数是size_t

2.许多int转换为char

3.将maxOutLen的默认值从80更改为70

* /

#if定义(__ STDC__)||定义(__ cplusplus)

#define VOID void

#define FUNC_1(t1,v1)(t1 v1)

#define FUNC_2(t1, v1,t2,v2)(t1 v1,t2 v2)

#define FUNC_3(t1,v1,t2,v2,t3,v3)(t1 v1,t2 v2,t3 v3)
#define TRIG_BACK_SLASH"?" "?" " /" / *三角形为\ * /

#define TRIG_POUND_SIGN"?" "?" " =" / *三角形为#* /

#else

#define VOID

#define FUNC_1(t1,v1)(v1)t1 v1;

#define FUNC_2(t1,v1,t2,v2)(v1,v2)t1 v1; t2 v2;

#define FUNC_3(t1,v1,t2,v2,t3,v3)(v1,v2,v3)t1 v1; t2 v2; t3 v3;

#define TRIG_BACK_SLASH" ?? /" / *三角形为\ * /

#define TRIG_POUND_SIGN" ?? =" / *三角形#* /

#endif

#include< stdio.h>

#include< stdlib.h>

#include< string.h>

#include< ctype.h>

#define MYstrncmp(a1,a2,a3)strncmp (a1,a2,(size_t)(a3))

static FILE * inF; static FILE * outF; static char * inLine = 0; static char *

lastToken = 0; static char * prevToken = 0; static int outCounter = 0; static

int inComment = 0; static int removeComment = 0; static int maxOutLen = 70-1

; static char * operatorString [] = {/ *按lenght排序! * // * 4 * /" %%%%",

/ * 3 * /" ..."," - > *","< < =",">> =",

#if defined(__ STDC__)||定义(__ cplusplus)

"?""?""(",/ * trigraph for" [" * /"?""?""" ;)",/ * trigraph for]" * /"?"

"?""!",/ * trigraph for|" * /?""?""''",* * trigraph for^ * /"?""?"

"<",* * trigraph for{" * /?""?"">",* / trigraph for}" * /?""?"" - ",

/ * trigraph for〜 * /

#else

" ??(&,'* trigraph for[" * /] ??",/ * trigraph对于] * /!??!,

/ * trigraph for|" * /??''",/ * trigraph for^ * /?? ??<",

/ * trigraph for{" * /??>",/ * trigraph for}" * /?? - ",

/ * trigraph for〜 * /

#endif

/ * 2 * /" - >"," ++"," - ","。 *","<<",">>","< =","> ="," ==","!= QUOT ;,"&安培;&安培;"," ||" ,

" * ="," / =","%="," + ="," - =","& =" ;," ^ ="," | ="," ::"," ##","<>","<%","% >",

"<:",":>"," %%",/ * 1 * /"!","% "," ^","&安培;"," * QUOT;,"(",")"," - "," + QUOT;," =" ;," {",

"}"," |","〜"," [","]",/ *" \\,* /" ;;",/ *" \''",* /":",/ *" \"",* /"< ;",">"

,"?",",","。"," /","#",/ * 0 * / 0,}; static void clean(VOID){if(inLine){

free((void *)inLine); inLine = 0;} if(prevToken){free(( void *)prevToken);

prevToken = 0;} if(lastToken){free((void *)lastToken); lastToken = 0;} if(

inF&& inF!= stdin){(void)fclose(inF); inF = 0;} if(outF&& outF!= stdout){ (

void)fclose(outF); outF = 0;}} static int getOpLen FUNC_1(char *,p){int i

; unsigned int len; for( i = 0; operatorString [i]; i ++){len = strlen(

operatorString [i]); if(strlen(p)> = len&&!MYstrncmp(p,operatorString [ i]

,len))return len;} return 0;} static void byebye(VOID){clean(); exit(-1

);} static void outOfMemory(VOID){(void)fprintf(stderr,"%s \ n",

" Out of memory!"); byebye();} static int endLine FUNC_1(char *,line){

int len = strlen(line); if(len == 0 || line [len-1]!=''\ n'')return 0; if(if) len> = 2

&& line [len-2] ==''\\''){line [len-2] =(char)0; return 0;} if(len> = 4&&!

MYstrncmp(line + len-4,TRIG_BACK_SLASH,3)){line [len-4] =(char)0; return 0

;} return 1;} static void addCharToLine FUNC_2(char,c,char **,line){int

len = strlen(* line); * line =(char *)realloc((void *)* lin e,(size_t)(len + 1 + 1

)); if(!* line)outOfMemory ();(* line)[len + 0] = c;(* line)[len + 1] =(char)0;}

static void readLine(VOID){int c; int len; if(inLine){free((void *)

inLine); inLine = 0;} inLine =(char *)malloc((size_t)1); if(!inLine)

outOfMemory(); * inLine =(char)0; while(!endLine(inLin e)){c = fgetc(inF);

if(c == EOF)break; addCharToLine((char)c,& inLine);} le n = strlen(inLine);

if(len)inLine [len-1] =( char)0;} static void forceNewLine(VOID){if(

outCounter){(void)fprintf(outF," \ n"); outCounter = 0; static int

isIdentifierLetter FUNC_1(char,c){return c!= 0&&(isalnum((int)c)|| c ==

' '_' '||ç==''


There is a LARGE number of syntax styles in most (if not all)
programming languages.

For example, one syntax style (my current one):

....
int main()
{
for (int i = 0; i < 50; i++)
{
cout << "Hello World!\n";
j = 2*i+1; //some weird calculation
}

return 0;
}

But I am thinking of a change, a change to a style more widely used in
programming languages. If I seem not to like it, I will return to my
current one... The new style is:

int main() {
for (int i = 0; i < 50; i++) {
cout << "Hello World!\n";
j := 2*i+1;
}

return 0;
}

I seem not to be really used to it now (cuz it''s just the beginning).
I was thinking to change because in many places I saw the second
style, so I suppose it''s better (looking).

WHAT IS YOUR FAVORABLE SYTLE???????????????? give an example if
necessary

解决方案


"Chris Mantoulidis" <cm****@yahoo.com> wrote in message
news:a8**************************@posting.google.c om...

There is a LARGE number of syntax styles in most (if not all)
programming languages.

For example, one syntax style (my current one):

...
int main()
{
for (int i = 0; i < 50; i++)
{
cout << "Hello World!\n";
j = 2*i+1; file://some weird calculation
}

return 0;
}

But I am thinking of a change, a change to a style more widely used in
programming languages. If I seem not to like it, I will return to my
current one... The new style is:

int main() {
for (int i = 0; i < 50; i++) {
cout << "Hello World!\n";
j := 2*i+1;
}

return 0;
}

I seem not to be really used to it now (cuz it''s just the beginning).
I was thinking to change because in many places I saw the second
style, so I suppose it''s better (looking).

WHAT IS YOUR FAVORABLE SYTLE???????????????? give an example if
necessary



There is no "best" coding style. Which coding style you choose is not
important, as long as it is consistent. It also helps if you use the same
coding style as everyone else around you. Of all the places I have worked
the first coding style prefered. Since I''m used to that style, code
formatted that way is easier to read for me than the second style. I expect
it to be the other way around for people used to the second style.

If you work alone choose whatever you like best. If you work in a group use
the coding style everyone else uses. Other than that I see no reason to
switch styles.

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl


On Thu, 11 Dec 2003 06:17:18 -0800, Chris Mantoulidis wrote:

I seem not to be really used to it now (cuz it''s just the beginning).
I was thinking to change because in many places I saw the second
style, so I suppose it''s better (looking).



Use the style you prefer when you work alone. Use the common style when
you work in a group.

At a minimum be consistent within one source file.

Tabs for indentation is evil, but not as evil as mixing tabs and spaces.

--
NPV

"the large print giveth, and the small print taketh away"
Tom Waits - Step right up


Chris Mantoulidis wrote:

There is a LARGE number of syntax styles in most (if not all)
programming languages.

For example, one syntax style (my current one):

...
int main()
{
for (int i = 0; i < 50; i++)
{
cout << "Hello World!\n";
j = 2*i+1; //some weird calculation
}

return 0;
}



with your example my funny coding style is:

int main(){for(int i=0;i<50;i++){cout<<"Hello World!\n";j=2*i+1;
//some weird calculation
}return 0;}

It''s obtained by the following C program:

/************************ File: cz.c **********************
It has been proved that the number of errors in a C or C++ program
is proportional to the number of lines into the source files.
This program dramaticaly reduce the number of errors,
reducing (up to 99%) the number of lines in your sources.
OBVIOUSLY a source code that is run by this program:
is semantic equivalent to the original
but it is less readable !
Try all forms:
cz cz.c cz_short.c
cz -256 cz.c cz_small.c
cz -30000 -X cz.c cz_atom.c
cz -0 cz.c cz_long.c
to obtain:
cz_short.c ( 200 lines long)
cz_small.c ( 118 lines long)
cz_atom.c ( 27 lines long)
cz_long.c (2746 lines long)
from:
cz.c ( 639 lines long)
Author: Dario Email: da***@despammed.com
************************************************** **********//*
Version History:
1.0 Dec 6 1994
Initial version
1.1 Dec 7 1994
1. Correct from:
sscanf(argv[i]+1, "%ld", &maxOutLen)
to:
sscanf(argv[i]+1, "%d", &maxOutLen)
2. Correct from:
static char * operator[] = {...
to:
static char * operatorString[] = {...
3. Operators added to operatorString:
%%%% ... <> <% %> <: :> %%
4. Introduced the function isIdientifierLetter
5. Changed from:
*n = *n+1;
to:
(*n)++;
6. Correct from
#if defined(__STDC__) || defined(__cpluscplus)
to:
#if defined(__STDC__) || defined(__cplusplus)
7. Many casts added to the result of memory allocators
8. Correct from:
static forceNewLine(void)
to:
static void forceNewLine(void)
1.2 Dec 12 1994
1. Recognize as preprocessor line a line starting with %%
2. Now may be also compiled by pre-ANSI-C compiler
1.3 Aug 04 1997
1. Third paramter of strncmp is a size_t
2. Many int casted to char
3. Changed the default for maxOutLen from 80 to 70
*/
#if defined(__STDC__) || defined(__cplusplus)
#define VOID void
#define FUNC_1(t1,v1) (t1 v1)
#define FUNC_2(t1,v1,t2,v2) (t1 v1, t2 v2)
#define FUNC_3(t1,v1,t2,v2,t3,v3) (t1 v1, t2 v2, t3 v3)
#define TRIG_BACK_SLASH "?" "?" "/" /* trigraph for \ */
#define TRIG_POUND_SIGN "?" "?" "=" /* trigraph for # */
#else
#define VOID
#define FUNC_1(t1,v1) (v1) t1 v1;
#define FUNC_2(t1,v1,t2,v2) (v1, v2) t1 v1; t2 v2;
#define FUNC_3(t1,v1,t2,v2,t3,v3) (v1, v2, v3) t1 v1; t2 v2; t3 v3;
#define TRIG_BACK_SLASH "??/" /* trigraph for \ */
#define TRIG_POUND_SIGN "??=" /* trigraph for # */
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MYstrncmp(a1,a2,a3) strncmp(a1,a2,(size_t)(a3))
static FILE*inF;static FILE*outF;static char*inLine=0;static char*
lastToken=0;static char*prevToken=0;static int outCounter=0;static
int inComment=0;static int removeComment=0;static int maxOutLen=70-1
;static char*operatorString[]={/* sorted by lenght! *//* 4 */"%%%%",
/* 3 */"...","->*","<<=",">>=",
#if defined(__STDC__) || defined(__cplusplus)
"?""?""(",/* trigraph for "[" */"?""?"")",/* trigraph for "]" */"?"
"?""!",/* trigraph for "|" */"?""?""''",/* trigraph for "^" */"?""?"
"<",/* trigraph for "{" */"?""?"">",/* trigraph for "}" */"?""?""-",
/* trigraph for "~" */
#else
"??(",/* trigraph for "[" */"??)",/* trigraph for "]" */"??!",
/* trigraph for "|" */"??''",/* trigraph for "^" */"??<",
/* trigraph for "{" */"??>",/* trigraph for "}" */"??-",
/* trigraph for "~" */
#endif
/* 2 */"->","++","--",".*","<<",">>","<=",">=","==","!=","&&","||" ,
"*=","/=","%=","+=","-=","&=","^=","|=","::","##","<>","<%","%>",
"<:",":>","%%",/* 1 */"!","%","^","&","*","(",")","-","+","=","{",
"}","|","~","[","]",/* "\\", */";",/* "\''", */":",/* "\"", */"<",">"
,"?",",",".","/","#",/* 0 */0,};static void clean(VOID){if(inLine){
free((void*)inLine);inLine=0;}if(prevToken){free(( void*)prevToken);
prevToken=0;}if(lastToken){free((void*)lastToken); lastToken=0;}if(
inF&&inF!=stdin){(void)fclose(inF);inF=0;}if(outF& &outF!=stdout){(
void)fclose(outF);outF=0;}}static int getOpLen FUNC_1(char*,p){int i
;unsigned int len;for(i=0;operatorString[i];i++){len=strlen(
operatorString[i]);if(strlen(p)>=len&&!MYstrncmp(p,operatorString[i]
,len))return len;}return 0;}static void byebye(VOID){clean();exit(-1
);}static void outOfMemory(VOID){(void)fprintf(stderr,"%s\n",
"Out of memory!");byebye();}static int endLine FUNC_1(char*,line){
int len=strlen(line);if(len==0||line[len-1]!=''\n'')return 0;if(len>=2
&&line[len-2]==''\\''){line[len-2]=(char)0;return 0;}if(len>=4&&!
MYstrncmp(line+len-4,TRIG_BACK_SLASH,3)){line[len-4]=(char)0;return 0
;}return 1;}static void addCharToLine FUNC_2(char,c,char**,line){int
len=strlen(*line);*line=(char*)realloc((void*)*lin e,(size_t)(len+1+1
));if(!*line)outOfMemory();(*line)[len+0]=c;(*line)[len+1]=(char)0;}
static void readLine(VOID){int c;int len;if(inLine){free((void*)
inLine);inLine=0;}inLine=(char*)malloc((size_t)1); if(!inLine)
outOfMemory();*inLine=(char)0;while(!endLine(inLin e)){c=fgetc(inF);
if(c==EOF)break;addCharToLine((char)c,&inLine);}le n=strlen(inLine);
if(len)inLine[len-1]=(char)0;}static void forceNewLine(VOID){if(
outCounter){(void)fprintf(outF,"\n");outCounter=0; }}static int
isIdentifierLetter FUNC_1(char,c){return c!=0&&(isalnum((int)c)||c==
''_''||c==''


这篇关于(编程)各种语法样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆