碼注釋,有些人說它太丑,也有些人說它是標準和良好的做法。在本文中, 列出了一些在編程中遇到的有趣的代碼注釋。
// Weed Effect !
這是雜草效應的意思?不是很懂,有誰知道,可以留言一下。
/**** 原文 *****/
//The following code was written by <developer name>.
// Unless it doesn't work, then I have no idea who wrote it.
/**** 自譯 *****/
// 以下代碼是由<developer name>編寫的。
// 除非它不起作用,否則我不知道是誰寫的。
/**** 原文 *****/
// Ad Index scheming and plotting - Those with
// heart conditions are advised to not continue
/**** 自譯 *****/
// 廣告索引的設計和繪圖模塊
// 建議不要深入閱讀,否則容得得心臟病
/**** 原文 *****/
// nobody read comments!
/**** 自譯 *****/
// 沒人會讀的注釋
/**** 原文 *****/
i++; // increment i
/**** 自譯 *****/
i++; // 自增 i
/**** 原文 *****/
// Magic. Do not touch.
/**** 自譯 *****/
// 這里已經結界,不要碰.
/**** 原文 *****/
// sometimes I believe compiler ignores all my comments
/**** 自譯 *****/
// 有時我相信編譯器會忽略我的所有注釋
/**** 原文 *****/
// I am not responsible of this code.
// They made me write it, against my will.
/**** 自譯 *****/
// 我對此代碼不承擔任何責任。
// 是他們強迫我讓我寫的,這已違背了我的意愿。
/**** 原文 *****/
//
// Dear maintainer:
//
// Once you are done trying to 'optimize' this routine,
// and have realized what a terrible mistake that was,
// please increment the following counter as a warning
// to the next guy:
//
// total_hours_wasted_here = 42
/**** 自譯 *****/
// 親愛的程序媛
//
// 一旦你嘗試“優化”此代碼,并意識到這是一個可怕的錯誤,
// 請增加以下計數器,以警告下一個人
// total_hours_wasted_here = 42
/**** 原文 *****/
# To understand recursion, see the bottom of this file
At the bottom of the file
# To understand recursion, see the top of this file
/**** 自譯 *****/
# 要了解遞歸,請參見此文件的底部
在文件的底部
# 要了解遞歸,請參見此文件的頂部
/**** 原文 *****/
// I will give you two of my seventy-two virgins if you can fix this.
/**** 自譯 *****/
// 如果你能解決這個問題,我就把我七十二個處女中的兩個給你。
/**** 原文 *****/
//Dear future me. Please forgive me.
//I can't even begin to express how sorry I am.
/**** 自譯 *****/
// 你好,未來帥氣的我,請原諒我。
// 我現在無法表達我的歉意,因為我寫下了這段代碼。
/**** 原文 *****/
//private instance variable for storing age
public static int age;
/**** 自譯 *****/
// 用于存儲年齡的私有實例變量
public static int age;
/**** 原文 *****/
const int TEN=10; // s if the value of 10 will fluctuate...
/**** 自譯 *****/
const int TEN=10; // 10 是會改變的值
/**** 原文 *****/
/* You are not meant to understand this */
/**** 自譯 *****/
/* 你不應該理解這一點 */
/**** 原文 *****/
/*
* TODO: Remove this function
function remove($customer_id)
{
$this->Customer->remove($id);
}
*/
/**** 自譯 *****/
/*
* TODO: 刪除函數
function remove($customer_id)
{
$this->Customer->remove($id);
}
*/
/**** 原文 *****/
//When I wrote this, only God and I understood what I was doing
//Now, God only knows
/**** 自譯 *****/
// 當我寫這段代碼,只有上帝和我知道這是在做什么
...
// 現在,只有上帝知道這段代碼在做什么
/**** 原文 *****/
// drunk, fix later
/**** 自譯 *****/
// 喝醉了,待會解決
/**** 原文 *****/
// I'm sorry.
/**** 自譯 *****/
// 我很抱歉
/**** 原文 *****/
// I am not responsible of this code.
/**** 自譯 *****/
// 我對此代碼不承擔任何責任。
/**** 原文 *****/
// I have to find a better job
/**** 自譯 *****/
// 我必須找到更好的工作
/**** 原文 *****/
// Joe is sorry
A few hundred lines later...
// Harry is sorry too
/**** 自譯 *****/
// 老五抱歉了
寫了幾百行代碼之后...
// 小五對不住了
/**** 原文 *****/
# Christmas tree initializer
toConnect = []
toRead = [ ]
toWrite = [ ]
primes = [ ]
responses = {}
remaining = {}
/**** 自譯 *****/
# 圣誕樹初始化器
toConnect = []
toRead = [ ]
toWrite = [ ]
primes = [ ]
responses = {}
remaining = {}
/**** 原文 *****/
Catch (Exception e) {
// who cares?
}
/**** 自譯 *****/
Catch (Exception e) {
// 管它呢?
}
/**** 原文 *****/
// IE7 update. this is still bad code, but IE8 is probably a long way off :)
/**** 自譯 *****/
IE7更新,這仍然是錯誤的代碼,看來 IE8 還有很長的路要走:)
/**** 原文 *****/
// If this code works, it was written by Paul DiLascia. If not, I don't know
/**** 自譯 *****/
// 如果這個代碼有效的話,它就是由 前端小智 編寫的。如果出錯了,我也不知道是誰寫的。
/**** 原文 *****/
// This comment is self explanatory.
/**** 自譯 *****/
// 這個注釋不言自明。
/**** 原文 *****/
int main(void)
/* Program starts here */
/**** 自譯 *****/
int main(void)
/* 程序從這里開始 */
/**** 原文 *****/
// I am not sure if we need this, but too scared to delete.
/**** 自譯 *****/
// 我不確定我們是否需要這個,但又害怕刪除
/**** 原文 *****/
/**
* Always returns true.
*/
public boolean isAvailable() {
return false;
}
/**** 自譯 *****/
/**
* 總是返回 true.
*/
public boolean isAvailable() {
return false;
}
/**** 原文 *****/
// Autogenerated, do not edit. All changes will be undone.
/**** 自譯 *****/
// 自動生成,不要編輯。所有的更改都將被撤銷。
/**** 原文 *****/
// hack for ie browser (assuming that ie is a browser)
/**** 自譯 *****/
// 破解ie瀏覽器(假設ie是一個瀏覽器)
/**** 原文 *****/
/////////////////////////////////////// this is a well commented line
/**** 自譯 *****/
/////////////////////////////////////// 這是一個很好的注釋
/**** 原文 *****/
// Mr. Compiler, please do not read this.
/**** 自譯 *****/
// 編譯先生,請不要讀取這個
/**** 原文 *****/
// All bugs added by David S. Miller
/**** 自譯 *****/
// 所有 bug 都是由 老王 添加的
/**** 原文 *****/
//If you're reading this, then my program is probably a success
/**** 自譯 *****/
// 如果你現在在認真詳細的閱讀這段代碼,那么寫的這段代碼應該是沒有問題的。
/**** 原文 *****/
Catch (Exception e) {
//eat it
}
/**** 自譯 *****/
Catch (Exception e) {
// 吃掉它
}
/**** 原文 *****/
//todo: never to be implemented
/**** 自譯 *****/
// todo:永遠不會執行
/**** 原文 *****/
// simply copied from another code
/**** 自譯 *****/
// 別問,問我也是從另一個代碼拷貝過來的
/**** 原文 *****/
//Please comment on your source code
/**** 自譯 *****/
// 拜托啦,請把你寫的代碼注釋一下
/**** 原文 *****/
# as you can see: I comment the code!
/**** 自譯 *****/
# 如你所見:我注釋了代碼!
/**** 原文 *****/
// if i ever see this again i'm going to start bringing guns to work
/**** 自譯 *****/
// 如果我再看到這個,我會帶槍去工作
def format_ticket_content(text, recursive = true)
if text.is_a?(TicketNote)
note = text
text = note.content
else
note = nil
end
## Safety pig has arrived!
text = h(text)
## _
## _._ _..._ .-', _.._(`))
## '-. ` ' /-._.-' ',/
## ) \ '.
## / _ _ | \
## | a a / |
## \ .-. ;
## '-('' ).-' ,' ;
## '-; | .'
## \ \ /
## | 7 .__ _.-\ \
## | | | ``/ /` /
## /,_| | /,_/ /
## /,_/ '`-'
##
/**** 原文 *****/
long long ago; /* in a galaxy far far away */
/**** 自譯 *****/
long long ago; /* 在遙遠的星系中 */
/**** 原文 *****/
try {
} finally { // should never happen
}
/**** 自譯 *****/
try {
} finally { // 這里永遠不會被執行
}
/**** 原文 *****/
/* Ah ah ah! You'll never understand why this one works. */
/**** 自譯 *****/
// 啊啊啊!你永遠都不會明白為什么這個方法有效。
/**** 原文 *****/
// this formula is right, work out the math yourself if you don't believe me
/**** 自譯 *****/
// 這個公式是正確的,如果你不相信我,自己動手算一下
/**** 原文 *****/
// This was clearly written under duress
/**** 自譯 *****/
// 這顯然是在脅迫下寫的
.=' ' .`/,/!(=)Zm.
.._,,._.. ,-`- `,\ ` -` -`\\7//WW.
,v=~/.-,-\- -!|V-s.)iT-|s|\-.' `///mK%.
v!`i!-.e]-g`bT/i(/[=.Z/m)K(YNYi.. /-]i44M.
v`/,`|v]-DvLcfZ/eV/iDLN\D/ZK@%8W[Z.. `/d!Z8m
//,c\(2(X/NYNY8]ZZ/bZd\()/\7WY%WKKW) -'|(][%4.
,\\i\c(e)WX@WKKZKDKWMZ8(b5/ZK8]Z7%ffVM, -.Y!bNMi
/-iit5N)KWG%%8%%%%W8%ZWM(8YZvD)XN(@. [ \]!/GXW[
/ ))G8\NMN%W%%%%%%%%%%8KK@WZKYK*ZG5KMi,- vi[NZGM[
i\!(44Y8K%8%%%**~YZYZ@%%%%%4KWZ/PKN)ZDZ7 c=//WZK%!
,\v\YtMZW8W%%f`,`.t/bNZZK%%W%%ZXb*K(K5DZ -c\\/KM48
-|c5PbM4DDW%f v./c\[tMY8W%PMW%D@KW)Gbf -/(=ZZKM8[
2(N8YXWK85@K -'c|K4/KKK%@ V%@@WD8e~ .//ct)8ZK%8`
=)b%]Nd)@KM[ !'\cG!iWYK%%| !M@KZf -c\))ZDKW%`
YYKWZGNM4/Pb '-VscP4]b@W% 'Mf` -L\///KM(%W!
!KKW4ZK/W7)Z. '/cttbY)DKW% -` .',\v)K(5KW%%f
'W)KWKZZg)Z2/,!/L(-DYYb54% ,,`, -\-/v(((KK5WW%f
\M4NDDKZZ(e!/\7vNTtZd)8\Mi!\-,-/i-v((tKNGN%W%%
'M8M88(Zd))///((|D\tDY\\KK-`/-i(=)KtNNN@W%%%@%[
!8%@KW5KKN4///s(\Pd!ROBY8/=2(/4ZdzKD%K%%%M8@%%
'%%%W%dGNtPK(c\/2\[Z(ttNYZ2NZW8W8K%%%%YKM%M%%.
*%%W%GW5@/%!e]_tZdY()v)ZXMZW%W%%%*5Y]K%ZK%8[
'*%%%%8%8WK\)[/ZmZ/Zi]!/M%%%%@f\ \Y/NNMK%%!
'VM%%%%W%WN5Z/Gt5/b)((cV@f` - |cZbMKW%%|
'V*M%%%WZ/ZG\t5((+)L\'-,,/ -)X(NWW%%
`~`MZ/DZGNZG5(((\, ,t\\Z)KW%@
'M8K%8GN8\5(5///]i!v\K)85W%%f
YWWKKKKWZ8G54X/GGMeK@WM8%@
!M8%8%48WG@KWYbW%WWW%%%@
VM%WKWK%8K%%8WWWW%%%@`
~*%%%%%%W%%%%%%%@~
~*MM%%%%%%@f`
'''''
/************************************************************
* *
* .=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-. *
* | ______ | *
* | .-" "-. | *
* | / \ | *
* | _ | | _ | *
* | ( \ |, .-. .-. ,| / ) | *
* | > "=._ | )(__/ \__)( | _.=" < | *
* | (_/"=._"=._ |/ /\ \| _.="_.="\_) | *
* | "=._"(_ ^^ _)"_.=" | *
* | "=\__|IIIIII|__/=" | *
* | _.="| \IIIIII/ |"=._ | *
* | _ _.="_.="\ /"=._"=._ _ | *
* | ( \_.="_.=" `--------` "=._"=._/ ) | *
* | > _.=" "=._ < | *
* | (_/ \_) | *
* | | *
* '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=' *
* *
* LASCIATE OGNI SPERANZA, VOI CH'ENTRATE * LEAVE EVERY HOPE, YOU COME IN
*************************************************************/
/**** 原文 *****/
// This was clearly written under duress
/**** 自譯 *****/
// 如果將來我讀到這篇文章,我會回到過去并自殺。
/**** 原文 *****/
// This was clearly written under duress
/**** 自譯 *****/
// 亂七八糟的 SQL語句,但它有效,所以請不要觸摸它
// .==. .==.
// //`^\\ //^`\\
// // ^ ^\(\__/)/^ ^^\\
// //^ ^^ ^/6 6\ ^^ ^ \\
// //^ ^^ ^/( .. )\^ ^ ^ \\
// // ^^ ^/\| v""v |/\^ ^ ^\\
// // ^^/\/ / `~~` \ \/\^ ^\\
// -----------------------------
/// 這是條龍
/**** 原文 *****/
// I from the future read this I'll back in time and kill myself.
/**** 自譯 *****/
// 這是垃圾代碼,但現在是凌晨3點,我需要把它修好。
// 我不確定我做了什么
如果你想被解雇,請將其刪除
// 切勿動以下代碼,否則我會踢你的 PP
作者:xor 譯者:前端小智 來源:medium 原文:https://medium.com/javascript-in-plain-english/30-funny-code-comments-that-will-make-you-laugh-1c1b54d4ab00
例
HTML 注釋:
<!--這是一個注釋,注釋在瀏覽器中不會顯示--><p>這是一個段落</p>
瀏覽器支持
所有主流瀏覽器都支持 <!--...--> 注釋標簽。
標簽定義及使用說明
<!--...--> 注釋標簽用來在源文檔中插入注釋。注釋不會在瀏覽器中顯示。
您可使用注釋對您的代碼進行解釋,這樣做有助于您在以后的時間對代碼的編輯。特別是代碼量很大的情況下很有用。
您也可以在注釋內容存儲針對程序所定制的信息。在這種情況下,這些信息對用戶是不可見的,但是對程序來說是可用的。一個好的習慣是把注釋或樣式元素放入注釋文本中,這樣就可避免不支持腳本或樣式的老瀏覽器把它們顯示為純文本。
<scripttype="text/javascript"><!--functiondisplayMsg(){alert("Hello World!")}//--></script>
注釋:命令行最后的兩個正斜杠(//)是 JavaScript 注釋符號。這確保了 JavaScript 不會執行 --> 標簽。
除了在源文檔中有非常明顯的作用外,許多 Web 服務器也利用注釋來實現文檔服務端軟件特有的特性。這些服務器可以掃描文檔,從傳統的 HTML/XHTML 注釋中找到特定的字符序列,然后再根據嵌在注釋中的命令采取相應的動作。這些動作可能是簡單的包括其他文件中的文本(即所謂的服務器端包含,server-inside include),也可能是復雜地執行其他命令去動態生成文檔的內容。
HTML 4.01 與 HTML5之間的差異
無。
標準屬性
<!--...--> 注釋標簽不支持任何標準屬性。
如需更多有關 HTML 標準屬性的信息,請訪問 標準屬性。
事件屬性
<!--...--> 注釋標簽不支持任何事件屬性。
如需更多有關 HTML 事件屬性的信息,請訪問 事件屬性。
如您還有不明白的可以在下面與我留言或是與我探討QQ群308855039,我們一起飛!
roughnotation是一款web頁面目標元素標記動畫注釋的組件,該組件十分適合展示類的場景。它非常輕巧,只有3.8kb大小。它在github擁有5.3k顆星,足可以見其受歡迎的程度。它的注釋方式多樣,包括:下劃線、盒狀、圓圈、高亮、水平劃除線、X型劃除線、方括號。
https://github.com/rough-stuff/rough-notation
npm install --save rough-notation
import { annotate } from 'rough-notation';
// Or using unpkg
// import { annotate } from 'https://unpkg.com/rough-notation?module';
const e = document.querySelector('#myElement');
const annotation = annotate(e, { type: 'underline' });
annotation.show();
*請認真填寫需求信息,我們會在24小時內與您取得聯系。