- Java 11 and 12:New Features
- Mala Gupta
- 248字
- 2021-07-02 12:27:02
Meaningful variable names
Type inference with var should be used responsibly. When you remove explicit data type from a variable declaration, the variable name takes the center stage. With inferred types, it is your responsibility to use descriptive and appropriate variable names, so that they make more sense in code. As you know, a piece of code is written once, but read many times.
For example, the following line of code won't make much sense to you or to your team members (especially with a big or distributed team) after a period of time:
var i = getData(); // what does getData() return? Is 'i' a
// good name?
The key questions are—what is the variable i used for? What does the method getData() return? Imagine the plight of the other team members that will work with this code after you leave.
Also, it doesn't help to define variable names that are mismatched with their purposes. For example, it doesn't make much sense to create a connection object named database and assign a URL instance to it, or to define a variable with the name query and assign a Connection instance to it:
var database = new URL("http://www.eJavaGuru.com/malagupta.html"); var query = con.getConnection();
- The DevOps 2.3 Toolkit
- GitLab Cookbook
- Python數(shù)據(jù)分析基礎(chǔ)
- PyTorch自動駕駛視覺感知算法實(shí)戰(zhàn)
- 薛定宇教授大講堂(卷Ⅳ):MATLAB最優(yōu)化計(jì)算
- Learning Firefox OS Application Development
- 老“碼”識途
- 軟件工程
- PhpStorm Cookbook
- Learning Raspbian
- C語言程序設(shè)計(jì)
- Getting Started with LLVM Core Libraries
- Python Programming for Arduino
- Mastering Leap Motion
- 零基礎(chǔ)學(xué)編程系列(全5冊)