Sunday, 12 February 2017

What to do for improve old projects?

 

 


In '08, before I graduated from college, I interned at a company. At that time, the boss took over a project, which was a web version of the management system for a subsidiary of PetroChina, and a classmate and I finished it with a hard scalp. The back end of this system uses c# web form, the front end of the ordinary html+css+javascript, the database uses sql server 2005, and the deployment server uses Microsoft Server 2008. Looking back at this system now, although the code is badly written and the architecture is badly written, it can work normally, which is occasionally some small bugs that are inexplicably difficult to solve. After all, it was my own code 5 years ago, when I was too tender, I didn't know a lot of things, and I didn't have much experience.

so if i were to upgrade this system now, or even redo it, what improvements would i make? it's an interesting topic, and if you can really find a lot of shops that can be improved, then it means that you've really improved over the years.

now it is really possible to make functional upgrades to this system. i thought about it for a while and will make improvements and adjustments in the next few aspects.

Use the latest Visual Studio IDE and install the ReShaper plugin. Now I have become a shortcut keyer, refactoring control. As the saying goes, if you want to do something, you must first use it. Good programmers, of course, use the best tools. The new Visual Studio has improved in terms of efficiency and smart tips. ReShaper is of course essential as a refactoring tool under .net.

host the code into github's private codebase, using git as a source control tool. previous projects used svn, using a company server for code hosting, while the company server was not so stable. as a distributed source control tool, git is free from the shackles of a central server, and has the characteristics of rapid creation, branch switching, local commit, etc., and is full of svn. as the world's largest code hosting center, github is convenient and practical, with the cheapest members 7$ per month and affordable.

Log important functions in the system. I think back then we wanted to record some program logs, and we had to write a simple log library ourselves. There are now many mature log frameworks that can be used by C#. Imagine how difficult it is to troubleshoot bugs if you don't have enough logs when your program is deployed on a server. The server can't let you restore the scene, can't debug, the only thing that can help is those logs. Of course, there is also a lot of knowledge in logging, such as log level settings, output settings, etc., which will not be elaborated here.

use transaction mechanisms to handle complex logic. there were a lot of concurrent operations in this system, and at that time i didn't know much about transactions, and i used some very lame methods to handle possible data anomalies. now i'll use a mature distributed transaction mechanism to handle these concurrency logics and make the program more robust.

USE TDD TO IMPROVE UNIT TEST COVERAGE. THERE WERE NO UNIT TESTS IN THE PREVIOUS SYSTEM, AND A SIMPLE PIECE OF CODE REQUIRED MANUAL VALIDATION OF THE STARTUP PROGRAM. THIS FEEDBACK IS TIME-CONSUMING AND NOT REPETITIVE. TEST-DRIVEN DEVELOPMENT ENSURES THAT THE CODE IS CONCISE, CORRECT, AND CAN GET FEEDBACK QUICKLY TO ENSURE TEST COVERAGE. WHEN ENCOUNTERING LEGACY CODE, YOU CAN ALSO ADD UNIT TESTS FIRST TO ESTABLISH A PROTECTION NET AND MAKE THE REFACTORING MORE CONFIDENT.

use webdriver for automated functional testing. once, before giving a demonstration to a customer, i changed a piece of code, but i didn't expect that this code just broke an important function that was demonstrated to the customer. this can be avoided if there are automated functional tests. automated functional testing increases confidence in the product, with every change under control.

write build scripts for continuous integration. even if only one person is working on this project, you should write a build script and apply continuous integration. this keeps every commit safe for you, and automating repetitive tasks frees your brain to focus on more important places.

automated deployment. each time you deploy a project to the server is a painful experience, you need to manually replace some files in the project, copy the files to the server, terminate the current server service.....which link error is a fatal blow. manual is not only inefficient, but also extremely error-prone. automating deployments by writing scripts can be done once and for all, and the tedious manual operations say goodbye.


Use Nuget as a dependency management tool. If you want to reference a third-party dependency and need to manually download and add it to your project from the web, you're out. As a Java programmer, build tools such as maven and gradle are standard, and they all provide automated management of dependencies. You just need to add a string to indicate which class library you want to use, and the downloads and references are all left to the management tools. Of course, there is a corresponding product in the C# world, that is, Nuget, and dependency management is no longer a headache.


Use c#'s own features, such as LINQ, delegates, functional programming, etc. Compared to the unenterprising Java language, C# does not know how many times stronger. Java was only officially introduced in the Java 8 version of Lambda, and C# LINQ has been out for many years. If you're still just using foreach when doing a list operation, you're too old-fashioned. List operations are nothing more than filter, map, sort... And C# has already provided us with a series of extension methods, such as Where, Select, Sort.... Poor Java can only use Guava, a third-party class library like Guava, to achieve the corresponding effect, and it is far less beautiful than the native features of C#. Since C# cites so many features every year, learn, master, and use them. Many people use the old native grammar of C# while saying that they are proficient in C#, which is really speechless. With so many good features not to use, we Java programmers are really envious and jealous.


Use some front-end frameworks and JavaScript frameworks. For me, I can't do enough to design a beautiful page. Don't be afraid, the designers have taken into account the feelings of the front-end incompetent, and front-end UI frameworks such as bootstrap are simply born for us. These are not only simple to use, the effect is obvious, but also come with a responsive design, which is really a sharp tool for the front-end white, and it is no longer a dream to realize their own exquisite Web site. JavaScript is not much to say, what jQuery, AngularJs, ExtJs.....a variety of framework class libraries emerge in an endless stream, covering all aspects of front-end development. Whether you want to draw, manipulate DOM elements, create single-page applications, use MVC architecture... In the javascript world you always have a variety of options. I think that in order to show a statistical chart in the web page, I used .net to draw a picture in real time in the background and load it into the foreground display, all of which were tears. Now, you just need to bind the data model to the chart control and get it done in minutes.


well, that's all there is to it. how to judge whether a programmer really has n years of work experience, rather than 1 year of work experience repeated n years? a good idea is to come up with a previous project and see what improvements he will make.


for programmers who have worked for many years, the knowledge and vision must be wide, so that they can be competitive. this depends on the usual learning and accumulation, but also good at thinking, how to do the things at hand better.

No comments:

Post a Comment