1) Production is all about load which will expose concurrency issues, load issues, memory and CPU issues. 生产环境的负荷会暴露并发、负荷,内存,cpu等问题 2) You will get a lot many scenarios in production that you might have thought in development. If think through process is not applied than most likely those scenario has not handled in production. 生产环境会有一些你开发时没有考虑到的场景 3) Different data input or incorrect data, one of classic problems in production is the data which gets input to your program, be it from upstream system or any other place you will get all sort of data and if your program doesn't handle those very likely it will suffer. 不同的数据输入源和错误的数据 4) Boundary conditions, this is some what related to above point data and scenarios but most of the boundary condition e.g. null, empty etc exposed in production. 边界条件,比如null,empty等 So if a code is written all these things and potentially domain specific things and can sustain test of production than it called a production quality code and believe me it takes a lot of experience, skill and think through process to write production quality code not just in first time even after two or three iteration but as a developer we should always strive for writing production quality code in first attempt. Now let's see how we can do that, what are the things we should keep in mind: 1) Get your requirements right, understand the problem , talk to user or business person as much as possible this will help you to find different scenario as early as possible. Many times business or user not tell you everything its not there fault but it doesn't come in mind right through. So if you are frequently speaking, discussing and presenting solution to them most likely they will ask questions, give feedback which eventually expose more scenario and subtle details. Here experience plays an important role. More experience or domain knowledge you, much better code you will write. 理解需求,知道问题所在,与需求方多交流尽早发现不同的场景,有时需求方并不知道他们需要什么,如果你能和他们多交流多展示解决方案,通常他们会给你反馈同时会暴露更多场景和细节。这里经验起重要作用,你的经验和行业知识越多,你写的代码就越好。 2) Think through, Think through and Think through. There is no substitute of this, it is more of a skill and art than science but you will get hold of this when you get more experience. For example if user says that you need replay capability in your program. You should be able to think of all possible scenarios where you need to replay and what could be required for that, what would be side effect of that. Does replay would be requested, what if the requesting system went down again, will you be able to re replay etc. 想通、想通、再想通。 3) Boundary condition, always think that you will get bad input , you will get null or empty, small or very large numbers, function may get called at wrong time etc. you can get rid of this by writing unit test for each boundary condition. 边界条件,做最极端最坏的打算 4) Concurrency, this is is the major culprit and big problem which exposes itself in production when due to load multiple thread gets triggered and access your program concurrently. With high speed low latency electronic trading system and with many other java system where its requirement to have a concurrent application this can only be addressed by proper design , if you get the design right you will safe other wise you will need to bear the pain of redesigning or rewriting code. You can also expose concurrency issue by doing load testing in early QA cycles. 并发,这个是生产环境中高负荷产生问题的罪魁祸首。 5) Exception handling, this is by far most important characteristic of production quality code, it must be able to handle exceptional scenario in clear cut predefined way. Whole program should never be crashed due to one single bad input or scenario. 异常处理的场景要进行预先定义清晰的划分 6) Recoverable, code should be able to recover itself in case of premature closing or crash. Though these are just some points which I am able to thought, there are lots more and it’s a constant process of improving yourself and I always strive for this. Please share how you guys write production quality code, what are things you guys keep in mind, what questions you guys ask to yourself and to user ? Code should be expandable。代码需要可扩展 System Locale 系统环境,编码
2012年1月12日星期四
怎样写“生产质量”的代码
订阅:
博文评论 (Atom)
没有评论:
发表评论