Soft_Job 板


LINE

本週主題 * 「屬性」該用哪個字? * Attribute, Property 有什麼不一樣? 結論:沒有一定的標準。 * 在哲理上 * 「由外部因素賦予此物件的屬性」,所謂 extrinsic property * 稱為 property, 也可稱為 attribute * 「此物件內在本質的屬性」,所謂 intrinsic property * 稱為 property * 在語源上 * attribute 偏向「賦予」;「由外部因素賦予此物件的屬性」 * property 偏向「本質」;「此物件內在本質的屬性」 * 在程式實作上,沒有一定的標準。 * 下面列舉了 C#, HTML, DOM 的例子。 --- * GitHub 討論 https://bit.ly/321ResR * Google 簡報 https://bit.ly/32DAoAD --- # Attribute, Property 有什麼不一樣? * 在哲理上 * 「由外部因素賦予此物件的屬性」,所謂 extrinsic property * 稱為 property, 也可稱為 attribute * 「此物件內在本質的屬性」,所謂 intrinsic property * 稱為 property * 在語源上 * attribute 偏向「賦予」;「由外部因素賦予此物件的屬性」 * property 偏向「本質」;「此物件內在本質的屬性」 ## Attribute * 語意:外部(extrinsic) / 關係(relational) 屬性 * 由「與其它物件的關係」賦予此物件的屬性 * 例如,一個物件的「重量」;由此物件所處的重力場賦予的屬性 * 語源: 14 世紀後期,動詞「賦予、指派」,名詞「對某人的評價」 * 在程式上 * 可表達物件、元素的屬性 * 常用來表達「屬性的屬性」 ## Property * 語意 * 內部(intrinsic) 屬性 * 物件本質上的屬性 * 例如,一個物件的「質量」 * 也可以代表 外部(extrinsic) / 關係(relational) 屬性 * 語源: 1300 年代,本質、特性 * 在程式上 * 可表達物件、元素的屬性 # Attribute, Property 該用哪個字? 在程式實作上,不同語言、框架、環境對於「物件屬性」這個觀念的心智模型多少 有出入,並沒有一定的標準。 我個人偏好 C# 的風格。 ## 以 C# 為例 * 在「為東西加註資料(metadata)」的情景下,用 `Attribute` * 例如, `DebuggerBrowsableAttribute` * 而「類別的屬性」,稱為 `Property` * 例如, `String.Length` ## 以 HTML / DOM 為例 HTML (attribute) / DOM (property) 則是用了不同的字來表達「東西的屬性」。 引用 https://stackoverflow.com/a/53924373 的例子: ``` <input id="the-input" type="text" value="Name:"> ``` * 假設使用者在此輸入欄位填上了 "foo" * 接下來以 `<input>` 代表此 HTML 元素(element) * 接下來以 `theInput` 代表此 DOM 物件 * 執行 theInput.value 會得到 "foo" * value 是 theInput 這個 DOM 物件的 property (屬性) * 執行 theInput.getAttribute('value') 會得到 "Name:" * `getAttribute()` 是 theInput 這個 DOM 物件的方法 * value 是 `<input>` 這個 HTML 元素的 attribute (屬性) ## 參考資料 * https://en.wikipedia.org/wiki/Attribute_(computing) * https://en.wikipedia.org/wiki/Property_(philosophy)#Intrinsic_and_extrinsic_properties * https://stackoverflow.com/a/53924373 * https://www.etymonline.com/word/attribute * https://www.etymonline.com/word/property * https://www.lexico.com/en/definition/attribute * https://www.lexico.com/en/definition/property 感謝參與 https://github.com/EngTW/English-for-Programmers/issues/25 討論 的網友。 --- 這週比較忙,只研究了一個題目。 XD --



※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 136.56.13.184 (美國)
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Soft_Job/M.1600400643.A.D04.html ※ 編輯: AmosYang (136.56.13.184 美國), 09/18/2020 11:44:41 ※ 編輯: AmosYang (136.56.13.184 美國), 09/18/2020 11:46:46
1F:→ yoche2000: 推 09/18 12:06
2F:推 hans1461: 推 09/18 12:08
謝謝 :)
3F:→ chatnoir: vue跟react都用props傳參數給child耶, 我要去發PR XDDD 09/18 12:17
我不熟 vue, react 及其架構理念;能不能談談你是為什麼想去發什麼樣的 PR ? :) ※ 編輯: AmosYang (136.56.13.184 美國), 09/18/2020 12:25:38
4F:→ krazy1101: React 的 props 官方文件表示 properties 的縮寫,但 09/18 12:29
5F:→ krazy1101: 行為比較像是從外部傳值進入元件,剛好跟你寫的定義相 09/18 12:29
6F:→ krazy1101: 反 09/18 12:29
謝謝你的說明 :) 這讓我想到 C# 語言中,類別(class)的 "property" 也是支援 setter/getter 。 或許這要看這些語言、框架的設計者有沒有留下紀錄它當初思路、考量的文件,才 能知道它為什麼要這樣設計、選用特定的字。
7F:推 easterday: 我也覺得attribute->內在,property->外在 09/18 12:40
8F:→ easterday: 這樣的用法比較多 09/18 12:41
(延續上面的討論) 或許可以這樣想: * 在哲理思維層級, * 東西有質量(mass);質量是東西的 內部(intrinsic) 屬性(property) * 東西存在,就有質量;質量不受外部因素影響 * 東西有重量(weight);重量是東西的 外部(extrinsic) 屬性(attribute) * 東西有重量,是因為「這個東西」與「這環境的重力場」的關係 * 東西的重量受外部因素「重力場」的影響 * 在程式實作層級,可能是寫成這樣: ```C# class Thing { public double MassInGrams { get; set; } public double WeightInGrams { get; set; } } ``` 從 C# 語言層級來看, `MassInGrams`, `WeightInGrams` 都是 `Thing` 這個 類別(class)的屬性(property)。 ※ 編輯: AmosYang (136.56.13.184 美國), 09/18/2020 13:32:10
9F:推 virdust2003: 認同這篇 09/18 13:18
謝謝你的欣賞 :) --- (延續上面的討論) 我修改了上面的原文 # 舊 * 語意:內部(intrinsic) 屬性 * 物件本質上的屬性 * 例如,一個物件的「質量」 # 新 * 語意 * 內部(intrinsic) 屬性 * 物件本質上的屬性 * 例如,一個物件的「質量」 * 也可以代表 外部(extrinsic) / 關係(relational) 屬性 # 參考資料 * https://en.wikipedia.org/wiki/Property_(philosophy)#Intrinsic_and_extrinsic_properties > An intrinsic property is a property that an object or a thing has of > itself, independently of other things, including its context. > An extrinsic (or relational) property is a property that depends on a > thing's relationship with other things. > The latter is sometimes also called an attribute, since the value of > that property is given to the object via its relation with another > object. ※ 編輯: AmosYang (136.56.13.184 美國), 09/18/2020 13:49:45
10F:推 chatnoir: 感謝k大幫我解釋 ~ 我只是開玩笑的 09/18 14:19
我覺得那是很有意思的題目,也讓我發現了我的文章最原始的版本寫得不夠清楚; 希望推文中的後續討論、補充說明有幫助 :) ※ 編輯: AmosYang (136.56.13.184 美國), 09/18/2020 14:37:57
11F:→ ChungLi5566: 對岸是翻成固有屬性跟自定義屬性 09/18 14:47
謝謝補充資訊 :)
12F:推 DCTmaybe: 請問有argument,parameter系列嗎? 09/18 15:08
有,可以參考 * https://webptt.com/m.aspx?n=bbs/Soft_Job/M.1597982849.A.9A7.html * 或 Google 簡報 https://bit.ly/3l161ey 第 17 頁 --- 這系列文章的列表: https://github.com/EngTW/English-for-Programmers 也有列出每個文章的主要關鍵字,可以用 CTRL-F 找你想查的字。
13F:推 CoNsTaR: argument, parameter 問題出在中文沒有適合的詞來翻 argu 09/18 17:07
14F:→ CoNsTaR: ment,所以只好都叫參數吧... 09/18 17:07
15F:→ Jockey66666: argument(引數) parameter(參數) 蠻多這樣翻的吧 09/18 20:08
是的,我查到的也是這樣翻: * 方法、函數宣告的是參數 (parameter) * 傳入方法、函數的是引數 (argument)
16F:推 LERICAL: 推 09/18 20:38
謝謝 :) --- 文章編輯說明;希望這樣子能更清楚 :) # 舊:「哲理、語意」混在一起 * 在哲理、語意上 * attribute 偏向「由外部因素賦予此物件的屬性」 * property 偏向「此物件內在本質的屬性」 # 新:「哲理、語意」分開來說 * 在哲理上 * 「由外部因素賦予此物件的屬性」,所謂 extrinsic property * 稱為 property, 也可稱為 attribute * 「此物件內在本質的屬性」,所謂 intrinsic property * 稱為 property * 在語源上 * attribute 偏向「賦予」;「由外部因素賦予此物件的屬性」 * property 偏向「本質」;「此物件內在本質的屬性」 ※ 編輯: AmosYang (136.56.13.184 美國), 09/18/2020 21:25:21
17F:→ KanzakiHAria: C++attribute從外面給屬性 vcproj property是本質 09/21 21:16
感謝提供實例 :)
18F:推 candycan: 講到「屬性」就會想到「設定」,好像很容易搞混… 09/22 12:56
是的。 在臉書那邊的討論有個很有意思的題目:「要怎麼表達『傑尼龜的屬性是水』?」 這時候就要分析「屬性」想表達的 語意 究竟為何 。 最後整理出來,比較完整的說法是 * "PokemonPowerType" 是「傑尼龜的屬性 (之一)」 * 傑尼龜的 Pokemon Power Type 是水。 那就可以視上下文脈絡,可以有像是以下的選擇: * 傑尼龜.PokemonPowerType = Water * 傑尼龜.PowerType = Water * 傑尼龜.Type = Water
19F:推 bug2: 謝謝分享 很有價值的討論與實用範例 09/25 10:18
謝謝 :) 有任何問題、建議,歡迎提出來討論 :) ※ 編輯: AmosYang (136.56.13.184 美國), 09/25/2020 11:38:04







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:e-shopping站內搜尋

TOP