糟糕代码的顶级警告标志? [英] Top warning signs of bad code?

查看:64
本文介绍了糟糕代码的顶级警告标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎大多数人都会在网站上找到JS,这是完全符合逻辑的
。但这也是一个很遗憾,因为该代码的大部分价格非常差。


我正在查看JS常见问题解答中的任何问题

标识要注意的警告标志,最简单明确地识别代码作者的事物

作为少于主人的东西艺术品。


我没有找到回复它的常见问题,但我认为常见问题

应该包含信息。所以,这是我的建议清单..


< FAQENTRY class =''more_Speculative_For_Discussion_OK?''>

1< SCRIPT LANGUAGE =''JavaScript''> //最后一个千年,还是另一个现实?

2 if(navigator.userAgent.indexOf(" IE"))//#FAQ4_26

3 eval(); //#FAQ4_40(通常)

4 if(.. == true)//!了解布尔值。

5< a href =" javascript :somefunction()"> //#FAQ4_24

6< NOSCRIPT> //如果缺少,脚本不会优雅地降级。

7 document.write("< p>重要内容.."); //提供内容。

< /常见问题>


您有什么看法?这些是前7名吗?

我错过了28个?


另外,为什么常见问题解答中不包含单词degrade,

优雅或noscript或(我想我可能已经用前两个找到错误的术语了,但是

没有提到NOSCRIPT?这让我很吃惊。)


顺便说一句 - Jibbering JS常见问题解答是我用过的唯一最好的常见问题解答*

,但我只需要一个hankerin''在

中提到它,或者至少为此做出贡献。 ;-)


*我有自己的(初出茅庐的)Java常见问题我希望有一天可以接受JS常见问题的质量,并且我是一个

最近扩展和改进的贡献者

ciwas常见问题。


-

Andrew Thompson
http://www.PhySci.org/codes/ Web& IT帮助
http://www.PhySci.org/ 开源软件套件
http://www.1point1C.org/ Science&技术
http://www.lensescapes.com/ 图像逃脱世俗

It seems most people get there JS off web sites, which is
entirely logical. But it is also a great pity since most
of that code is of such poor quality.

I was looking through the JS FAQ for any question that
identifies the warning signs to look out for, the things
that most easily and clearly identify the author of code
as something less than a master of the art.

I did not find an FAQ that answered it, but I think the FAQ
should contain the info., so, here is my proposed list..

<FAQENTRY class=''more_Speculative_For_Discussion_OK?''>
1 <SCRIPT LANGUAGE=''JavaScript''> // last millenium, or another reality?
2 if (navigator.userAgent.indexOf("IE")) // #FAQ4_26
3 eval(); // #FAQ4_40 (usually)
4 if (..==true) // !understanding boolean.
5 <a href="javascript:somefunction()"> // #FAQ4_24
6 <NOSCRIPT> // If missing, the script does not degrade gracefully.
7 document.write("<p>Important content.."); // delivering content.
</FAQENTRY>

What is your opinion? Are these the top 7?
Which 28 did I miss?

Also, why does the FAQ not contain the words "degrade",
"graceful" or "noscript" (I guess I might have been
looking for the wrong term with the first two, but
no mention of NOSCRIPT? That surprised me.)

BTW - The Jibbering JS FAQ is the single greatest FAQ*
I use, but I just have a hankerin'' to get mentioned in
it, or at least contribute to it. ;-)

* I have my own (fledgling) Java FAQ that I hope might
approach the quality of the JS FAQ one day, and am a
contributor to the recently expanded and improved
c.i.w.a.s. FAQ.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane

推荐答案

* Andrew Thompson *在comp.lang.javascript中写道

[ snip]
*Andrew Thompson* wrote in comp.lang.javascript:
[snip]
< FAQENTRY class =''more_Speculative_For_Discussion_OK?''>
1< SCRIPT LANGUAGE =''JavaScript''> //最后一个千年,还是另一个现实?
2 if(navigator.userAgent.indexOf(" IE"))//#FAQ4_26
3 eval(); //#FAQ4_40(通常)
4 if(.. == true)//!了解布尔值。
5< a href =" javascript :somefunction() "> //#FAQ4_24
6< NOSCRIPT> //如果缺少,脚本不会优雅地降级。
7 document.write("< p>重要内容.."); //提供内容。
< /常见问题>

您有什么看法?
<FAQENTRY class=''more_Speculative_For_Discussion_OK?''>
1 <SCRIPT LANGUAGE=''JavaScript''> // last millenium, or another reality?
2 if (navigator.userAgent.indexOf("IE")) // #FAQ4_26
3 eval(); // #FAQ4_40 (usually)
4 if (..==true) // !understanding boolean.
5 <a href="javascript:somefunction()"> // #FAQ4_24
6 <NOSCRIPT> // If missing, the script does not degrade gracefully.
7 document.write("<p>Important content.."); // delivering content.
</FAQENTRY>

What is your opinion?



[snip]


只需快速记录(或七个):


Re:#6:我个人倾向于仅在角色中使用javascript

可选 - 例如在非强制性的辅助能力。在这样的情况下,不需要noscript元素,但仍然有优雅的后备(通过HTML或Web服务器)。我不认为

我曾在开放的WWW环境中使用过noscript元素来提供

替代功能,只作为一个空元素来阻止简单化<来自哭泣犯规的可访问性测试工具!


由于可以隐含的事情,我不确定是否正在惩罚#4
转换为布尔值。


8. document.getElementById(" myId")。s​​tyle.color ="#ff3333" ;; //不是

在使用它们之前测试方法和属性

9. document.myFormName.myTextInputName.value =" dummy" ;; //使用

层次结构快捷方式,这些快捷方式在非IE浏览器中可能无法正常工作。

(注意:我真的需要检查现代浏览器如何处理这样的

件事)

10.试图在WWW

环境中使用仅限IE的方法和属性。

11使用''InnerHTML''可以被认为是不好的风格,但它比其他替代品更有用(虽然可滥用)。

12. onblur,onfocus, onchange - 通常用于通过

让用户感到惊讶,使表单控件以意想不到的非标准方式运行。

-

Andrew Urquhart

- 常见问题: http://www.jibbering.com/faq/

- 存档: http://groups.google.com/groups?grou...ang.javascript

- 与我联系: http://andrewu.co.uk/contact/


[snip]

Just a quick note (or seven):

Re: #6: I personally tend to use javascript only in roles that are
optional - e.g. in a non-compulsory assistive capacity. In such
circumstances a noscript element is not required, yet there is still
graceful fallback (either via HTML or the web server). I don''t think
I''ve ever used a noscript element in an open WWW environment to provide
alternative functionality, only as an empty element to stop simplistic
accessibility testing tools from crying foul!

I''m unsure of chastising #4 owing to the things that can be implicitly
cast to a Boolean.

8. document.getElementById("myId").style.color = "#ff3333"; // Not
testing for methods and properties before using them
9. document.myFormName.myTextInputName.value = "dummy"; // Using
hierarchy shortcuts that may not work as intended in non-IE browsers.
(NB: I really need to check up on how modern browsers cope with such
things)
10. Attempting to use IE-only methods and properties in a WWW
environment.
11. Use of ''InnerHTML'' can be considered bad style, but it is
significantly more usable (though abusable) than the alternatives.
12. onblur, onfocus, onchange - usually used to surprise the user by
making form controls behave in unexpected non-standard ways.
--
Andrew Urquhart
- FAQ: http://www.jibbering.com/faq/
- Archive: http://groups.google.com/groups?grou...ang.javascript
- Contact me: http://andrewu.co.uk/contact/


周一,20日2004年9月00:37:59 GMT,Andrew Urquhart写道:


(AT)
On Mon, 20 Sep 2004 00:37:59 GMT, Andrew Urquhart wrote:

(A.T.)
6< NOSCRIPT> //如果缺少,脚本不会正常降级。
6 <NOSCRIPT> // If missing, the script does not degrade gracefully.
Re:#6:我个人倾向于只在角色中使用javascript
可选 - ..


那一个需要澄清,我建议JS不需要
*完全*可选。

(最后鼓励作者来更好地

最少文档缺少< NOSRCIPT>标记,如果它意味着在WWW上下文中使用
。)

4 if(.. ==真的)//!理解布尔。
Re: #6: I personally tend to use javascript only in roles that are
optional - ..
That one requires clarification, I would suggest it is
not required for JS that is *completely* optional.
(Ultimately it might be better to encourage authors to at
least document lack of <NOSRCIPT> tag, if it is meant to
be used in a WWW context.)
4 if (..==true) // !understanding boolean.



由于可以隐式地转换为布尔值的东西,我不确定是否正在惩罚#4。


I''m unsure of chastising #4 owing to the things
that can be implicitly cast to a Boolean.




我可能写得不正确,或表达了很糟糕,我的意思是指示测试是真的

计算结果已经''真''。


你添加的其他点非常好,谢谢。


-

Andrew Thompson
http://www.PhySci.org/codes/ Web& IT帮助
http://www.PhySci.org/ 开源软件套件
http://www.1point1C.org/ Science&技术
http://www.lensescapes.com/ 图像逃脱mundane



I may have written that incorrectly, or expressed it
badly, I meant to indicate testing for true when
the result of a computaion was already ''true''.

The other points you added were excellent, thank you.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane


Andrew Thompson写道:
Andrew Thompson wrote:
似乎大多数人都把JS关闭到网站上,这完全是合乎逻辑的。但这也是一个很大的遗憾,因为大多数代码的质量都很差。


不仅仅是这样吗?

我正在查看JS常见问题解答,以确定任何可以找出警告标志的问题,最容易和最清楚地识别代码作者的东西
作为不是艺术大师的东西。

我没有找到回复它的FAQ,但是我认为常见问题
应该包含信息。所以,这是我提议的列表..


类似于识别坏脚本的快速指南。

< F ... Y class =''more_Speculative_For_Discussion_OK?''>
1< SCRIPT LANGUAGE =''JavaScript''> //上个千禧年,还是
另一个现实?


< SCRIPT LANGUAGE =''JavaScript1.2''> - 更能说明已过时

和不明智的创作。有效的HTML问题(虽然我支持并且

支持它)更加含糊,因为LANGUAGE属性永远不会直接损害HTML浏览器中的脚本本身。实际上它应该被认为是不好的包含多余的吗?虽然一旦确定了b / b $ b $多余的含义,但是它会倾向于省略语言

属性。


如果要包括在内脚本''隐藏''与HTML评论将

也必须进入。

2 if(navigator.userAgent.indexOf(" IE"))// #FAQ4_26


是。

3 eval(); // #FAQ4_40(通常)


是。

4如果(.. == true)//!了解布尔值。


也许(它肯定表明了对

布尔值的本质的可疑把握,这对程序员来说不是一个好兆头)。

5< a href =" javascript :somefunction()"> //#FAQ4_24


我从未真正想到那个表示糟糕的

脚本。但是,既然你提出它就有资格(考虑到许多

的原因*从不*使用该构造(至少执行纯粹的

副作用函数))。

6< NOSCRIPT> //如果缺少,脚本不会优雅地降级。


出乎意料,因为看起来反过来实际上是正确的。使用NOSCRIPT

将成为清理退化的障碍。问题是

而不是有两种可能性,脚本或noscript,那里

实际上是三种:支持脚本功能,脚本功能

不受支持且没有脚本执行。 NOSCRIPT无法解决浏览器支持javascript(并且已启用)的情况。

但不支持脚本要使用的功能。编码

面对浏览器缺乏功能而导致干净降级

脚本将倾向于否定使用NOSCRIPT标签作为
不支持/不可用时,
降级仍然可用。


Jim已经请求了,而且我已经完成了写作,常见问题解答页面

说明解释NOSCRIPT标签的实用性。


有效清洁降级的主要策略是将

HTML中的重要内容,并使用

脚本从那里操作它。脚本失败(出于任何原因)往往会在HTML中保留所有可用的内容。

内容。成功

执行脚本然后可以删除并替换该内容,

将其转换为可能需要的b / b
的主动脚本GUI组件,或任何类似的行动。

NOSCRIPT标签中不需要任何其他内容,并且用户无需访问

重要内容。

7 document.write("< p>重要内容.."); //提供
内容。


是的,但是: -


if(featureX&& document.write){

文件.write(''< input type =" button" onclick =" useFeatureX()">'');

}


- 有赞成的论据,所以它不是 - document.write - 而是

而不是写的是什么。

< / F. .. Y>

你有什么看法?这些是前7名吗?
我错过了哪28个?


应包括通过对象推断检测的浏览器。


未能适应用户选择的字体大小和覆盖的样式<带有用户样式表的
可能是候选人(虽然没有多少脚本会通过这些标准来获得
)。


可访问性也可能是候选人,键盘操作是一个明显的首要考虑因素(可能会被认为是一个过度的标准,因为它在世界大部分地区都不是法律要求,

并且无法用键盘主动操作脚本不是

始终是可访问性的障碍(有替代策略)。

另外,为什么常见问题解答中不包含单词degrade,
graceful或noscript(我想我可能一直在寻找前两个错误的术语,但是
没有提到NOSCRIPT?这让我很吃惊。)


我想我有xplained为什么noscript可能不会出现。

降级,干净,优雅或其他,是一个脚本设计问题,

可能超出了快速答案部分的适当范围。

顺便说一句 - Jibbering JS常见问题解答是我使用过的最好的常见问题解答*
我只是想在其中提及它,或者至少有助于它。 ; - )
It seems most people get there JS off web sites, which is
entirely logical. But it is also a great pity since most
of that code is of such poor quality.
Isn''t it just?
I was looking through the JS FAQ for any question that
identifies the warning signs to look out for, the things
that most easily and clearly identify the author of code
as something less than a master of the art.

I did not find an FAQ that answered it, but I think the FAQ
should contain the info., so, here is my proposed list..
Something like a quick guide to identifying bad scripts.
<F ... Y class=''more_Speculative_For_Discussion_OK?''>
1 <SCRIPT LANGUAGE=''JavaScript''> // last millenium, or
another reality?
<SCRIPT LANGUAGE=''JavaScript1.2''> - is more indicative of out of date
and ill-informed authoring. The valid HTML question (while I support and
endorse it) is more ambiguous as the LANGUAGE attribute will never
directly harm a script in an HTML browser in itself. Should it actually
be considered bad to include the superfluous? Although once
superfluousness is identified the sane will tend to omit the language
attribute.

If this is to be included then script ''hiding'' with HTML comments will
have to go in as well.
2 if (navigator.userAgent.indexOf("IE")) // #FAQ4_26
Yes.
3 eval(); // #FAQ4_40 (usually)
Yes.
4 if (..==true) // !understanding boolean.
Maybe (it certainly demonstrates a questionable grasp of the nature of
boolean values, and that is not a good sign in a programmer).
5 <a href="javascript:somefunction()"> // #FAQ4_24
I have never actually thought of that one as indicative of bad
scripting. But since you bring it up it does qualify (given the many
reasons for *never* using that construct (at least to execute pure
side-effect functions)).
6 <NOSCRIPT> // If missing, the script does not
degrade gracefully.
Unexpected as it might seem the reverse is actually true. Using NOSCRIPT
will tend to act as a barrier to clean degradation. The problem being
that instead of there being two possibilities, script or noscript, there
are actually three: scripted features supported, script features
unsupported and no script execution. NOSCRIPT cannot address the
circumstances where the browser supports javascript (and it is enabled)
but does not support the features that the script wants to use. Coding
for clean degradation in the face of the browser''s lack of features for
the script will tend to negate the use of NOSCRIPT tags as that path of
degradation remains available when scripting itself is
unsupported/unavailable.

Jim has requested, and I am part way through writing, a page for the FAQ
notes explaining how little practical use NOSCRIPT tags are.

The main strategy for effective clean degradation is to put the
important content in the HTML and manipulate it from there using
scripts. Failure of the script (for any reason) will tend to leave that
content in place in the HTML where it is available to all. Successful
execution of the script can then remove and replace that content,
transform it into the actively scripted GUI components that may be
wanted, or any similar action. No need for any additional content in
NOSCRIPT tags and no holes in the user''s ability to access that
important content.
7 document.write("<p>Important content.."); // delivering
content.
Yes, but:-

if(featureX && document.write){
document.write(''<input type="button" onclick="useFeatureX()">'');
}

- has arguments in its favour, so it is not the - document.write - but
rather a question of what it is that is written.
</F ... Y>

What is your opinion? Are these the top 7?
Which 28 did I miss?
Browser detecting by object inference should be included.

Failing to adapt to the user''s choice of font size and overridden styles
with User style sheets might be candidates (though not many scripts will
pass those criteria).

Accessibility might also be a candidate, keyboard operation being one
obvious first consideration (possibly that would be considered an
excessive criteria as it isn''t legally required in much of the world,
and the inability to actively operate a script with the keyboard is not
always a barrier to accessibility (there are alternative strategies).
Also, why does the FAQ not contain the words "degrade",
"graceful" or "noscript" (I guess I might have been
looking for the wrong term with the first two, but
no mention of NOSCRIPT? That surprised me.)
I think I have explained why "noscript" might not be expected to appear.
Degradation, clean, graceful or otherwise, is a script design issue that
probably goes beyond what is appropriate in the quick answers section.
BTW - The Jibbering JS FAQ is the single greatest FAQ*
I use, but I just have a hankerin'' to get mentioned in
it, or at least contribute to it. ;-)



< snip>


如果您想保证您的姓名与常见问题解答相关联

你可以为一些主题的笔记写一篇文章,你有经验/专业知识(或者愿意大量研究

做好)(并经过同行评审)。编写Java小程序脚本可能

成为您的主题。 ;-)


Richard。


<snip>

If you want to guarantee your name appears in association with the FAQ
you could write an article for the notes on some subject where you have
experience/expertise (or are willing to put a lot of research into
making good) (and subject to peer-review). Scripting Java applets might
be your subject. ;-)

Richard.


这篇关于糟糕代码的顶级警告标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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