How do I develop and maintain more than 8000 lines of code components


How do I develop and maintain more than 8000 lines of code components


  • I’m in mingyuanyun. We are the largest real estate company in ChinaSaasplatform
  • Any system will have legacy projects, and the larger the company, the more such projects there will be
  • There are many component lines, many native events, and the technology stack has just startedReact0.14The version comes up,UIComponent library is also a large number of use of the old component library
  • Business is extremely complex, extremely complex!

Why a large number of 8K lines or even 1W lines of code

  • The business logic design of a single page is too complex to split
  • Component splitting is not considered when implementing business logic, or component splitting is not detailed enough
  • The component is not pure enough. As a component, the best state is onechild, parents(Parent component)Tell it how to do it, and it should do it (that is, the specific business logic is implemented internally by the component, but the implementation of which business logic should be controlled by the parent component)
  • There is a lot of computational logic and the encapsulation of pure function is too low. If the encapsulation of pure function is high, it can be usedFAASeven to the extent thatServerlessTo solve this problem

How to maintain iterations

  • People familiar with the business sort out the main line of the core business, after all8KMultiple lines of code, it is impossible to comb all clear. But the main line should be clear
  • Gradual reconstruction, continuous reconstruction. If you use the latest technology this year, it may look like a very old technology in three years. Only continuous, gradual, from part to whole reconstruction can catch up with the trend of the times and have a good development experience
  • Business logic is inextricably linked, as I wrote this time500 linesThe code can’t be found50MultipleBUGThis component only adds ten lines of code (just a function). It has a lot to do with the unfamiliar business. It is necessary to sort out and output the main line document of the whole core business.
  • Strictly follow one-way data flow, do not use dirty data, this is the bottom line。 The old component 8K has many lines and lots of dirty data, for example: = 'ooo'
  • Component split, no more than 500 lines. Strictly speaking, a component can’t exceed 200 lines of code, which I did in the companywebhookDetected, as long as beyond the enterprise wechat will be all informed and@Corresponding code pusher.
  • Eliminate side effects and try to encapsulate pure functions without side effects. Originally, the business should not be placed in front-end processing. This is also for the sake of the futureFAASandServerlessPrepare for the change
  • Firmly believe that the ancestral code is stableDon’t try to modify the ancestral code. Existence is reasonable. If the person who wrote the code has left, don’t touch his code. Some codes are hard to read and unreasonable, but there must be his implementation logic( Unless you are 100% sure, but who can say absolutely? A big online accident, especially when it comes to the amount of money, can’t be resisted by ordinary developers.)

How do I develop and maintain more than 8000 lines of code components


  • I haven’t written an article during this period, mainly because the company is busy and the study plan hasn’t been completed
  • Near the national day, I don’t send any papers recently. It will be exported next month1-2piece
  • Now, I’m going to repair my car. I scraped an Audi A6 the night before yesterday. I feel heartbroken.