在循环/异常中为变量名使用单个字符 [英] Using single characters for variable names in loops/exceptions

查看:150
本文介绍了在循环/异常中为变量名使用单个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经与同事讨论了在某些情况下在单个字母变量名中使用单字母变量名,我们都不同意这一点。



在我看来,我有三种使用单字母变量名的方案:




  • 循环 - i for i = 0; i <10; i ++){...}

  • C#中的Lambda表达式 - x / y / z .Where(x => x == 5)

  • 异常 - e try {...} catch(ExceptionType e){/ *' * /}



这些是只有



我的同事对例外和循环提出了以下参数:




  • i - 这不意味着什么。

  • - 这是英语中最常见的字母。如果你想搜索解决方案的异常,你会发现很多不期望的实例 e



我接受这些参数,但有retort,如果一个人不知道 i 意味着在一个for循环,那么他们可能不应该一个程序员。这是一个非常常见的术语循环和异常,如 e 。我还提到,如果有人想要,他们可以在异常情况下搜索 catch



我意识到这是主观的,但是,然后,可以认为编码标准只是 - 意见,尽管学术界的意见。



我会很高兴,将转发结果给他,但宁愿我们(我们的公司)继续使用单一的编码标准,而不是有两个开发人员对于使用什么有不同的意见。




解决方案

我不是指任何东西



是的。这是在for循环或计数器中的索引。



e是英语中最常用的字母。如果你想搜索解决方案的异常,你会发现很多不期望的实例e



这只是甚至不做任何感。如果您想要查找异常的实例,为什么要搜索 e



Serioulsy,我只是笑到任何出现这些论点的人。 在这些情况下表示 i e 它们是普遍接受的惯例



编辑 - 此问题提醒我 this wtf


I've had a couple of discussions with a co-worker about the use of single letter variable names in certain circumstances inside our codebase, at which we both disagree.

He favours more verbose naming convention for these, and I do not.

There are three scenarios in my opinion where I use single letter variable names:

  • Loops - i for(int i = 0; i < 10; i++) { ... }
  • Lambda expressions in C# - x/y/z: .Where(x => x == 5)
  • Exceptions - e: try { ... } catch(ExceptionType e) { /* usage of 'e' */ }

These are the only scenarios where I would use it, and I obviously use more verbose naming conventions elsewhere.

My colleague put forward the following arguments for exceptions and loops:

  • i - it doesn't mean anything.
  • e - it's the most common letter in the English language. If you wanted to search the solution for exceptions, you'd find lots of undesired instances of e.

I accept these arguments, but have retorts that, if one does not know what i means in a for loop, then they probably shouldn't be a programmer. It's a very common term for loops and exceptions, as is e. I have also mentioned that, if one wanted, they could search for catch in the case of the exception.

I realise that this is subjective, but then, one could argue that coding standards are just that - opinions, albeit opinions by academics.

I would be happy either way, and will forward the results to him, but would rather that we (our company) continue to use a single coding standard, rather than have two developers with different opinions on what to use.

Thanks in advance.

解决方案

i doesn't mean anything

Yes it does. It's the index in a for loop or counter.

e is the most common letter in the English language. If you wanted to search the solution for exceptions, you'd find lots of undesired instances of e

This just doesn't even make any sense. Why would you search for e if you wanted to find instances of Exception?

Serioulsy, I'd just laugh at anyone who came out with these arguments. Everyone knows what i and e represent in these scenarios. They are universally accepted conventions. It sounds to me like your colleague is just trying to be a smart-ass.

Edit - This question reminded me of this wtf.

这篇关于在循环/异常中为变量名使用单个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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