Abstract I will write what I felt about being unaware of the contents in Python, C, and C ++.
For C and C ++
int a=8;
How often do you declare variables?
In this case, it is an integer type, so I think I will write it while thinking that "a number can be entered".
On the other hand, with Python
a=8
That's ok.
"For the time being, create a variable to put numbers in."
It's very easy, isn't it?
Consider displaying a value with a simple example.
If C
printf("%d",a);
-output-
8
It will come out.
"I have to be aware that some numbers will come out ..."
To you!
Good news!
With python
print(a)
-output-
8
Is coming out.
It's convenient for debugging for the time being.
In C ++
std::cout<<a;
-output-
```8```
is.
It may be the trend of the times that you don't have to be aware of the type.
## Demerit
It's okay when something goes wrong, but when displaying in octal (I'm talking about such a scene?)
In python
~~a=0o8~~
-Additional part-
Excuse me. It's an octal number, so it's 10.
@shiracamus Thank you for pointing out.
-So far-
```py
a = 0o10
print('%o' % a)
Must be written.
In C ~~printf("%x",a);~~ -Additional part- Excuse me. It was a hexadecimal number. @shiracamus Thank you for pointing out. -So far-
int a = 010;
printf("%o", a);
In C ++
int a = 010;
std::cout << std::oct << a;
It is ok if you write.
~~ Like this ~~ -Additional part- The example was not good, so I will cancel it. -So far- When the python in advance or to write any program policy is not determined exactly I got the impression that it was quite difficult to rewrite. On the other hand, I think it's easy to write when the policy is decided.
There are advantages and disadvantages to not being aware of the contents of the data. The merit is that the system does it without being aware of troublesome number conversion. The disadvantage is that you don't know what the contents are because you are not aware of it. I wonder if there are advantages and disadvantages.
Python is convenient if the policy is decided, but it may be difficult to write if there is a specification change.
It may be easier to understand if you cover it with variable naming.
"If you devise this way, the contents will be easy to understand from the variable name." If you have any questions such as "Isn't the writing style bad in the first place?", Please comment.
Recommended Posts