What those lousy codes taught me. _ Data structure

Source: Internet
Author: User
(previous posts, turn to CSDN) If you're a programmer, you don't have any interest in what I write, you can skip to the last sentence.
In the Wednesday, I was doing my job as usual, sneaking around to learn some ror. A teacher let a classmate asked me to help look at the program, said that the program compiles not through ... First of all, this project team project is a geological-related mapping software, most of the program design to oil data, and some computer graphics things, is with the oil cooperation, there are about 8, 9 years of appearance, no test. Hundreds of thousands of lines of code should be available.
I looked at the situation where the compiler appeared: OMG ... Hundreds of compilation errors. Next to the students are very calm, skilled notes off a few seem to be the newly written documents ... Well, that's better, says there are two types of duplicate definitions:
Me: If there is no test, then how should also add a file to compile it once. Teacher: This is not the key, the key is the duplicate definition of the data, make very old fire.
All right
There is probably a problem with this code (I'm streamlining it):
Datatypea and Datatypeb are types of enum defined in two different header files, representing the same physical meaning of the data ... There are a few files that contain these two header files
Me: Why there are two different types of data that represent the same thing. Teacher: A is the data structure defined in the original program, B is our newly written library, we do not want the new library to rely on the old program ... So we can continue to add new libraries to implement new features ... I (Heart OS): Really do not rely on it.
Before I started I didn't notice a name was Datatypea, and the other was datatypeb. I thought all is a, just add a ifndef, expect the speed to solve the problem ... The result is,,, No. Holy shit .....
How does a vertical in a verticlal conflict in the root B?

This project is really too big, compile all a long time, I wrote a small demo, to speed verification of this grammatical problem. Well. Or not, it seems to be a grammatical problem ...
After looking through the data, I know that the enum belongs to pod (plain old data) ... The type name of the enum has no namespace ...
Well, the problem has been found ...
Why would you call that bad code teach me something? Because I don't think I would normally use an enum. Why.
I asked the classmate a very simple question: Will you judge in some place whether the value of the enum type is vertical or horizon, and then calculate the different methods according to the result of the judgment. Classmate: Will ah I: would not such a judgment more than one place. Classmate: Well, yes. Me: There are some algorithmic changes for vertical or horizon. Classmate: Have I: Do you think you change the time is very bitter B.
Classmate: There are ... Classmate Trance met bosom friend ...

The reason why I didn't use the enum was almost half the explanation. The most important point:
Good code to train people's thinking, bad code to exercise people's grammar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.