"uw"是什么? STM32示例中的变量名开头意味着什么? [英] What does the "uw" mean at the beginning of variable names in STM32 examples?

查看:332
本文介绍了"uw"是什么? STM32示例中的变量名开头意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我阅读STM32示例代码时,我看到很多以uw开头的变量.例如:

As I read STM32 example code I see a fair number of variables that begin with uw. Ex:

static __IO uint32_t uwLsiFreq = 0;
__IO uint32_t uwCaptureNumber = 0;
__IO uint32_t uwPeriodValue = 0;
__IO uint32_t uwMeasurementDone = 0;

一切背后都有含义或故事. uw在这里是什么意思?

Everything has a meaning or a story behind it. What does uw mean here?

示例源:STM32Cube_FW_F2_V1.7.0/Projects/STM32F207ZG-Nucleo/Examples/IWDG/IWDG_Example/Src/main.c.
下载链接->单击获取软件" "STM32CubeF2"旁边的按钮.

Example Source: STM32Cube_FW_F2_V1.7.0/Projects/STM32F207ZG-Nucleo/Examples/IWDG/IWDG_Example/Src/main.c.
Download link --> click "Get Software" button next to "STM32CubeF2".

推荐答案

好的,我想发表我自己的更完整的答案.感谢@njuffa在我的问题下方的评论中指出可能:uw代表某种匈牙利符号",感谢@ PeterJ_01为指出的CEO Overflow在此问题上有一些见解,多亏@Sigve Kolbeinson在PeterJ_01的回答中指出,Stack Overflow的首席执行官的名字叫Joel Spolsky(在链接中找到),他实际上并不讨厌匈牙利符号,但是相反,它只是使它的有限和损坏的形式感到不高兴[Systems Hungarian]得到了一段时间的关注,并为我们提供了实际的

Alright, I'd like to post my own, more complete answer. Thanks to @njuffa for pointing out in a comment below my questions that "Probably: uw stands for 'unsigned word' in some sort of Hungarian notation," thanks to @PeterJ_01 for pointing out that the CEO of Stack Overflow has some opinions on the matter, and thanks to @Sigve Kolbeinson for pointing out in a comment under PeterJ_01's answer that the CEO of Stack Overflow's name is Joel Spolsky (as found in the link), he actually doesn't hate Hungarian notation, but rather is just upset a limited and corrupted form of it [Systems Hungarian] got traction for a while, and for giving us the actual link to the article so we can learn more and read the article ourselves.

uw当然在逻辑上必须表示无符号字",在这种情况下,字"为32位.知道这一点后,我在阅读代码时变得更加清晰,并且消除了对名称的混淆,因此我很高兴知道这一点.

uw at the beginning of many STM32 example variables certainly must logically mean "unsigned word," where a "word" is 32 bits in this case. Knowing this adds a lot of clarity as I read the code, and removes some confusion about the names, so I'm glad to know this.

在这种情况下,这是系统匈牙利语的一种用法,通常不建议使用具有显式类型的语言(例如C和C ++),因为它是多余的并且几乎没有价值.与此形成对比的是 Apps Hungarian (我在下面介绍),Joel Spolsky(Stack Overflow的首席执行官)

In this case, this is a type of Systems Hungarian usage, which is frequently discouraged for languages which have explicit types, such as C and C++, since it's redundant and adds little value. Contrast this to Apps Hungarian, which I describe below, which Joel Spolsky (CEO of Stack Overflow) strongly promotes as a way to help make "wrong code look wrong."

  1. 匈牙利符号存在(我之前不知道),并指在每个变量和/或函数名称的开头添加一些额外字符以提供有关变量或函数的其他信息的概念,例如其用途,其类型 ,或其返回类型.
  2. 这在无意中也回答了我有关FreeRTOS命名约定的问题.现在我知道了!他们也使用[主要是系统]匈牙利表示法.这是一些链接.请注意,在第一个链接中,您将看到FreeRTOS中所有匈牙利符号用法的列表.这种表示法几乎完全是Systems Hungarian表示法,但是当它们指定文件的名称时,也可​​以说使用了一点Appsungs Hungarian表示法,其中在函数或宏名称内定义了函数和宏.
  1. Hungarian notation exists (I didn't know about it before), and refers to the concept of adding a few extra characters at the beginning of each variable and/or function name to provide additional information about the variable or function, such as its purpose, its type, or its return type.
  2. Inadvertently this answered my question about FreeRTOS naming conventions too. Now I know! They use [primarily Systems] Hungarian notation as well. Here's some links. Note that in the first link you'll see a list of all of the Hungarian notation usages in FreeRTOS. This notation is almost entirely Systems Hungarian notation, but arguably uses a little bit of Apps Hungarian notation too when they specify the name of the file in which functions and macros are defined right inside the function or macro name.
    • FreeRTOS Hungarian Notation
    • what is v and x means in freeRTOS task creating or used in it?
    • https://www.freertos.org/FreeRTOS-Coding-Standard-and-Style-Guide.html#NamingConventions
  • Systems Hungarian 本质上是对匈牙利"表示法最初意图的破坏,这种想法是在其创建者查尔斯·西蒙尼(Charles Simonyi)的描述中错误地使用类型"而不是种类" ().查尔斯(Charle)的初衷是将其他信息编码为变量名,这不是编程语言本身所固有的.但是,匈牙利语表示基本上是将变量的类型存储到变量名中.例如:unsigned long myVar现在变为unsigned long ulMyVar.多数人似乎认为这要么用途有限,要么完全一文不值.乔尔·斯波克斯(Joel Spolksy)不是这种形式的匈牙利表示法的拥护者,,如他在文章中所述,但他强烈推荐 Apps匈牙利语风格.其他意见可以在Wikipedia文章的重要意见"部分中找到.
  • Apps匈牙利语描述了将其他信息存储在变量名前面的概念,该信息很难以其他方式推断出来,例如使用us表示" u nsafe s 调整"和s表示"safe s 调整".许多人对这种方法感到更加中立,或者喜欢并推广这种方法. Stack Overflow的首席执行官Joel Spolsky和Steve McConnel都认为这是个好主意,并推广使用.
  • Systems Hungarian is essentially a corruption of the original intent of "Hungarian" notation that came about when it's creator, Charles Simonyi's, mistakenly used the word "type" instead of "kind" in his description of it (source). Charle's original intent was to encode additional information into variable names that isn't inherent in the programming language itself. However, Systems Hungarian notation says basically to store the variable's type into the variable name. Ex: unsigned long myVar now becomes unsigned long ulMyVar. Most people seem to argue this is either of limited use or completely worthless. Joel Spolksy is not a proponent of this form of Hungarian notation, as indicated in his article, but he is strongly for Apps Hungarian style. Other opinions can be found in the "Notable opinions" section of the Wikipedia article here.
  • Apps Hungarian describes the concept of storing additional information into the front of a variable name which can NOT otherwise be easily deduced, such as using us to mean "unsafe string" and s to mean "safe string". Many people either feel more neutral towards this method, or like it and promote it. Both Joel Spolsky (CEO of Stack Overflow) and Steve McConnel think it's a good idea and promote its usage.

请注意,以下是 Joel的有用摘录文章:

某人在某处阅读了Simonyi的论文,他在其中使用了类型"一词,并认为他的意思是像类一样的类型,就像在类型系统中一样,就像编译器进行的类型检查一样.他没有.他非常仔细地准确解释了类型"一词的含义,但没有帮助.损坏了.

Somebody, somewhere, read Simonyi’s paper, where he used the word "type," and thought he meant type, like class, like in a type system, like the type checking that the compiler does. He did not. He explained very carefully exactly what he meant by the word "type," but it didn’t help. The damage was done.

Apps匈牙利语具有非常有用,有意义的前缀,例如"ix"表示数组的索引,"c"表示计数,"d"表示两个数字之间的差异(例如"dx"表示宽度"),等等.

Apps Hungarian had very useful, meaningful prefixes like "ix" to mean an index into an array, "c" to mean a count, "d" to mean the difference between two numbers (for example "dx" meant "width"), and so forth.

系统匈牙利语具有不太有用的前缀,例如,"l"代表long,"ul"代表"unsigned long","dw"代表双字,即,实际上,是一个无符号的长整数.在Systems Hungarian中,前缀告诉您的唯一信息是变量的实际数据类型.

Systems Hungarian had far less useful prefixes like "l" for long and "ul" for "unsigned long" and "dw" for double word, which is, actually, uh, an unsigned long. In Systems Hungarian, the only thing that the prefix told you was the actual data type of the variable.

这是对西蒙尼的意图和做法的微妙但完全的误解...

This was a subtle but complete misunderstanding of Simonyi’s intention and practice...

(添加了重点)

这篇关于"uw"是什么? STM32示例中的变量名开头意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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