避免语言关键字冲突 [英] Avoiding Language Keyword Conflicts

查看:96
本文介绍了避免语言关键字冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你们如何避免您的语言中的关键字冲突?

How do you guys avoid keyword conflicts in your language?

例如,我正在创建一个类(VB 2008)以保存我们生成的某些报告的所有配置变量.自然,变量之一是日期".当然,您不能有任何与关键字相同的名称.在VB 2008中,您可以选择用[]括住冲突的单词并进行修复,但我一直认为这是一种技巧.有什么建议?用来避开常见关键字的名字是什么?

For example, I'm creating a class (VB 2008) to hold all the configuration variables for some reports we generate. Naturally, one of the variables is "Date". And of course you can't have anything named the same as a keyword. In VB 2008 you do have the option of surrounding a conflicting word with []'s and fix it but I've always seen that as a hack. Any suggestions? What are your names to get around common keywords?

帮助可视化的代码...

Code to help visualize...

Dim m_Title As String

Dim m_Date As String

Public Property Title() As String
    Get
        Return m_Title
    End Get
    Set(ByVal value As String)
        m_Title = value
    End Set
End Property


Public Property [Date]() As String
    Get

    End Get
    Set(ByVal value As String)

    End Set
End Property 

推荐答案

可能会考虑变量的更具体的性质吗?

Probably think about more specific nature of the variable?

在您的示例中,日期"可以是创建日期"或发布日期"或其他任何内容.如果您发现变量名过于琐碎,则可能是您简化了代码(甚至混淆了代码).创建一个清晰但简洁的变量名称,以帮助您的同事.

From your example, the "Date" can be "Created Date" or "Posted Date" or anything else. If you find your variable names too trivial, you may be oversimplifying (or even obfuscating) your code. Help your coworkers by creating a clear but concise variable names.

这篇关于避免语言关键字冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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