关于使用My作为类名前缀的意见

发布于 2024-08-04 08:31:56 字数 84 浏览 3 评论 0原文

就我个人而言,我从来不喜欢类的 MyObject 命名。我猜现状会同意,但我想看看争论的另一面,以及它是否有任何有效性。

Personally, I've never liked the MyObject naming of classes. I would guess that the status quo would agree but I'd like to see the other side of the argument and if there's any validity to it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

八巷 2024-08-11 08:31:56

“我的”已被我使用,请使用其他内容

'My' is already used by me, use something else

一花一树开 2024-08-11 08:31:56

我从未见过它在生产代码中完成,尽管我敢说它存在。

它就像元语法变量“foo”和“bar”一样 - 它通常用作真实姓名的占位符。

例如,如果我知道某人有自己的从 Form 派生的类,但我对此一无所知,则代码示例将使用:

public class MyForm : Form

我当然会采取坚定的立场反对不过它是真正的代码:)

I've never seen it done in production code, although I dare say it exists.

It's like the metasyntactic variables "foo" and "bar" - it's usually used as a placeholder for a real name.

So for example, if I know that someone has their own class deriving from Form, but I don't know anything else about it, a code example would use:

public class MyForm : Form

I'd certainly take a firm stance against it for real code though :)

三人与歌 2024-08-11 08:31:56

我想它接近可接受的一个实例是,如果您以“My”为前缀的类是内部类(即在另一个类中声明的私有类)。我不确定是否有任何管理内部类的命名约定,但这可能是区分的一种方法。

I suppose one instance where it would be close to acceptable is if the class you're prefixing with "My" is an inner class (i.e a private class declared within another class). I'm not sure if there are any naming conventions governing inner classes, but this could be one way to differentiate.

够运 2024-08-11 08:31:56

据我所知,My 是示例代码中使用的前缀,表示“你的东西放在这里”。

它有点像foo。仅供教学用途。

As far as I've ever seen, My is a prefix used in sample code that indicates "your stuff goes here".

It's kind of like foo. Teaching purposes only.

半枫 2024-08-11 08:31:56

我在两种情况下使用过 My:

  1. 早在我在学校的第一堂编程课上时
  2. 当我正在做基本的“hello world”应用程序来学习语言时

,但从未在生产甚至伪生产代码中使用过。

I've used My in 2 situations:

  1. Way back when in my first programming classes in school
  2. When I am doing basic 'hello world' applications to learn a language

but NEVER in production or even pseudo-production code.

青衫负雪 2024-08-11 08:31:56

我会在生产代码中避免使用它,您的类型名称应该反映其应该执行的功能。

我在修补/破解第三方代码时使用过几次,例如将 Controller 替换为 MyController 以表明这是一个黑客,应该进行处理小心,还有蝙蝠。

I'd avoid it in production code, your type name should reflect the function its supposed to perform.

I've used it a couple of times when patching/hacking third party code, for instance replacing Controller with MyController to make it clear it is a hack, that should be approached with caution, and a bat.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文