What rules do developers use for variable names?

Asked 2 years ago, Updated 2 years ago, 113 views

I'm studying Python, but the code I made has passed

The difficulty of recognizing is coming up as a big problem.

I think annotations are very important, but while thinking about how to make general variables readable,

I thought it would be good to make variables easier to recognize.

For example, I want to create a variable that stores (headline length/2) when the length of the post title is too longWhen you do

For me,

length_of_divided_post_name = post_name/2

I thought about making it like this, but the name of the variable seemed too long, so it was not easy to write it like this.

That's all I'm saying

len_post_name =

I wonder if it'll be easy to recognize later on.

If you search for variable nomenclature on the Internet, you can only find camelCase, snake_case, etc.

It doesn't say how to actually make a meaning.

I didn't get a clear answer when I asked my friends or seniors.

If you're in the field or have your own neat rules,

Please give me some advice.

naming-convention

2022-09-22 19:44

3 Answers

There is a convention for each language, but as you said, there will be a lot of things like camelCase and snake_case. It depends on the decision, but the development environment these days is so developed that it is difficult to say that the long variable name or method name is a flaw. Personally, rather than using short words to reduce the length, I think it is important to deliver a clear meaning because it is automatically supported even if it is a little long.


2022-09-22 19:44

Those things are up to you. We need to decide the domain first.

Do you want the member to be a user or a member in the domain In the above example, should the length be len or length...This is what we decide.


2022-09-22 19:44

It's good to do it with post_name or post.name.

The logic of reducing the length in half because it is long must be in the class to make the code easier to read.

It's better to organize it from an oop perspective.


2022-09-22 19:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.