Merken

Rewriting 12-Year-Old Code

Zitierlink des Filmsegments
Embed Code

Automatisierte Medienanalyse

Beta
Erkannte Entitäten
Sprachtranskript
so why did I choose this picture for the presentation because that's what old called does it blows up in your face when you least expect it so many was
initially then the developer a problem I'm a teacher advisor and I own a company called out and so I organize a conference in at Qualcomm to so let's imagine
you inherited a 10 year old called base where sometimes 12 sometimes 15 right so welcome to the beginning so you have a 15 year old called base so and you came to this sucks I really admire bravery because to deal with 15 called takes some some so what what was the Web like 15 years ago just situated because we like to hates on this cold cold and the old practices that are really bad but we have to understand when it was written
and what what what web development was all about so 15 years ago it was 2 thousand so obviously was the
Y 2 K but that's when I will you probably know but that's when people realize that 2 digits for storing year is no longer adequate because now with 2 thousand you need to know digits so it it out of his doesn't support to Monday edges on the sorting is all wrong a bunch of problems so Google launched and words the will was already already existed and large and words before that I don't know
how they were making any money and then there was Twitter then
was no Facebook there was no iTunes MySpace was really cool the and so will yes wealth in the CDs that we got in the mail it was per frame
it was around 2000 and today we tried to when we laugh at Internet Explorer 6 but it didn't exist yet it was still Internet Explorer 5 and I remember when red before that I was using Netscape and who who uses Netscape Navigator anymore it had this gray background by default soul websites were like it and I think it was heck CCC and it was this light gray background all pages um I think he was only starting to be equal
so before there was an ascendant while ICQ it was it was the thing some people still remember their ICQ number to this day and so it Ciosek pseudo rights 2004 so if you were able to achieve rounded corners you were really cool and back in the day to do rounded corners you have probably to do a table
goes right now gives and stuff so playing as you know you remove the borders of the new you put 3 by 3 grid and then you put little corners here and there and then the content in the middle and if you wanted some nested corners and and then you will have to put another table in that cell and so the shadows in shuttle where I didn't try to the shadows that she was just that it seemed like rocket science so yeah this is what it was like a
enthusiasm to so many it still looks pretty lean today but there was no Yahoo news it was just the directory and then the idea of male is to have my yellow account from that day and then this this was 600 pixels wide 600
pixels wide just let that sink in for a moment that was the standard people use so the next step screens to be too big so maybe the expected the screen to be maybe hundred pixels wide maybe so they may decide 600 pixels wide and measured you so you're cold was written around that time the code that you just inherited was written in that area so don't expect it to be also like today from in computer sciences well Harry had all the concepts but it didn't quite applied to web development because it was new those people were new and they didn't quite know what they were doing so my objectives with this
presentation is to give you a whole lot of advice share some stories and show you how I solve some of the challenges with the old called so that you can avoid the mistakes that I made you can reduce mistakes in your own decisions you can increase the development speeds you can reduce the technical debts and avoid getting stuck because often with legacy what happens is that it things just don't mix together and you end up being stopped
because of an Virgin mismatch and the new version of disabled some feature and the old Cold doesn't supported so we cannot upgrade divergence so that we can use the shining features in other areas of the color and I also want to increase your confidence because with those stories no seeing how other people struggle with it and how this all the problems we will help you increase your confidence when dealing with legacy because they're not really that hard problems is is that you need to take the time in the profession correct let's have some fun before
we dive into the hardest
stuff the FIL local called cells so
this is just an example of table names that I've seen so let's say you have users but in the same database you might have a table called customer 601 1 is chloro and the other 1 is singular so you have that Mexican requite remember which 1 it is and sometimes you have 2 parts to the name and 1 is plural and the other is singular and sometimes it's reversed to ever quite remember you always have to look it up and sometimes you use an underscore or something you know so user profile in 1 word sometimes you get 7 which is the French news service but you will notice in french fries he just read it not if you if you also speak french you can get OK this is this was french but you know there's no hints anywhere that this is French especially when you start mixing French and English because network doesn't exist in French was a so now you start mixing languages and sometimes there are
words in 1 language that means 1 thing but in another it means something else you don't know which languages so the complexes lost but see this a lot of it's yeah it's quite simple and pleasant to the with centimeters from the hardest part but you know it's annoying the OK German
French and English and Russian Russian years that I I I I guess they speak Russian but I wouldn't even know the technical terms in russian that can be funny posted and so some of the some of the table names are written in Cyrillic so this is great you even have that on your keyboard you we would know where to find them in press call copy-paste here all you can do is copy paste and hope for for the best and sometimes you have things that give you a false sense of security so when you read this line you can certainly understand that no I don't know if you will work with speech fever ational entities takes the inputs and conversely entities to like the the ampersand and stuff so it's basically strips that science but I've seen people use that in order to secure or
filter the input to weights on and XSS attacks cross-site scripting attacks so they do that but it doesn't protect you from certain things because not everything is an HTML character so you could still have an SQL injection with that it doesn't
protected but the word clean is misleading
so they used the word clean and maybe it's like in included filed 10 levels down so you don't know where it's actually happening and then you see old clean dollar so you you assumed that the content of this of this variable is clear but maybe it's not and so you assume things you work with the cold and then you started being the parameter wall well this is totally secure what is happening of of course you want to concatenate the SQL query forget prepared statements and a shot in a in a query and yes so I
see a lot of includes file that includes 5 files on
top and then those files include other files but I see include but you it's require wants because at some point the developer loses doesn't want to be the same for all twice so this lose track of what's the include the might of might as well just include everything stands at all to loading is overrated him so they would just include a whole bunch of things and especially functions like and I remember that when I started working with PHP
around 2001 many um it and I was very common it was very common to and including functions file which contains a bunch of functions has no concept of object-oriented programming and it's very hard to ultimate test like that because you don't have concept of use yes it's a function but in the end just what people think about moving around he cannot through set of the state correctly squared difficulty says that some the hardest thing to unit test it makes things more difficult than you know things like that so where you you have and if if water ID is greater that's the news this SQL so you just the SQL equal something but otherwise as to equal something else then want what happens if I that water what happened something change some some business logic change something change but you know what because obviously from at so now you when whenever you try to give things you are in a lot of
trouble because you're not not question what's happening and all this of course all the SQL and HTML and the PHP it's all in 1 file most of the time that and so whenever find something like this I call it a the weakness that they usually bookmarks for later because if something blows up somewhere this that will probably be the 1st thing I will investigate this is a high risk statement this a risk area that is so if something blows up somewhere is a good chance that the answer lies in this
In this so the start refactoring
but in there are a lot of dangers the challenges of obstacles 1 of the things is that
it can take too long but the customer wants the feature now not necessarily a month from now or a year from they want something now they don't they don't think about refactoring they just see to keep moving forward we may have acquired the called base from another company and so the the start of the Indian company with this coal-based based this starting billing customers started doing something with it and then things break word there of business changes and now they have to do things differently we have to bill according to new rules the need to add a new new plans new new new ways of calculating things so 1st of all the extent of the country now they have to start charging taxes and if you've ever dealt with taxes and I know that's around the area of essentialist only there's like 400 different tax goes so it's almost like you know from district to that streets that tax golden here is that I don't know how they do it but you know there's a whole bunch of zip codes in my database and it associates to a whole lot of as a cold but if you do that internationally that's a lot of text goes to so it can take very long to refactor something like that so refractory code that is so fragile that you're you're not sure if you can touch this line of code without provoking a chain reaction that will break everything and because there are no tests there it tests are your safety net and you don't have a safety net so you will cross on a on a string between 2 mountains and you know don't you can always fall down and there's nothing to capture so that's how you feel it's it's really really
intimidating sometimes and you can take too long because you have to be very careful about every everything is change in the call because it can have a big impact so 1 of the things I notice also that is whenever somebody attempts to fool right it's almost always fails sometimes it to the scale of the person but often simply because fully rights and reason my experience don't quite work it has to be progressive simply because the client keeps expecting those new changes those improvements new features to the client has expectations and you cannot say rewrites on 1 side and then keep dealing with that fragile legacy at the same time because you're trying to get away from it so you you you get stuck and so progress every rights are very good approach and I'll show you many ways in which it has been achieved in companies so whenever you rights new cold so cold like a new class a new module you going to rewrite a chunk of time whenever you do that's that's new golden can run side by side with the existing applications they just put a few classes here and then call that instead of the old code and then the old code you can remove and their tools that can sniff and say whether other parts of the cold are referring to that school that you want to remove don't just removed because you assume it's no longer needed if you see in a database column that you think you might no longer need a really check out it sometimes they're not to remove just in case and then once you are almost done with the rewrite it will be very obvious because you can just run unit tests and you can see what's being executed in which coal is there then you just created out of what it's like when you want to add to clean something that's really really messy what you do is they take everything out he puts the clean things on 1 side and the ratings on the other and then you can create more easily than if you were to do this 1 by 1 so sometimes it's so new called that's is is written in the same language but sometimes it's call this region in a completely different language so for example 1 of my stories OSHA is moving from a speaker classic to PHP PHP 5 and is the classic hasn't been supported since I believe 2003 so it's it's has been discontinued a long time ago and so they have to move from the language to a new language so how do you run all this side by side in their ways to do that and 1 of the ways is to use things like more variety more the
alias different languages are actually fairly easy to
run side by side because sometimes you're limited to 1 version of the language persistent but if they're 2 different languages they don't interfere with each other I with speech needs a lot more difficult to run 2 versions of the same machine so the idea of same and different programming language when you rewrites as some of them I guess more more difficult things when you have those
2 applications there any connect to the same database all languages have connected and methods that allow you to connect databases read files that's kind easy so the only thing that remains is you know we're your sessions for hi you can access that and sometimes straightforward it's in the database it's great the file that's also not too bad and some and in some special area because of the power how this language was used to handle it clearly show you some examples of that as well another
difficulty is a you can lose the same you can break staff and it's it's an unsettling feeling that you have so much power so much control of your disposal but at the same time you don't really control anything because you don't know how it works how things are impacted so you're always afraid that whatever change of 1 to make is going to break everything or you can execute a script and then stuff will disappear from a database so always you back up that's that's the 1st rule in the dual back up whenever you do as you roll out a new patch whenever you want to execute some SQL to maybe of upgrade greatest schema always make
a backup before you do anything on the old code and we use things 2 things can and you can go wrong very quickly how ICT environments where you can simulate your deployments so before you go to the production of and for you you made the change at this that locally but similarly how you will apply that patch to the production environment and that's what staging is for just to show people to the client here you can click you can see changes I made us also to simulate those and those migration that you will do whether you're affecting me a database or change something on a file system we want to be able to played at once and then make sure that you have not broken anything and then you just repeat that's on the production system so copy the production system settings to a stage environment and continue from there the ultimate test cost so we you were painting you call that you're right you should start it can also there are also ways where you can test previously written code and whenever possible and then when you refactor you make sure that whatever changes you made a actually affecting anything but of course you use probably don't want to go in and start with just unit testing everything is it can be a very long time and also because the owner of the colleges business selling know how things are in supposed to work with that is a bond or a normal behavior this usually no documentation nobody but nobody from from when the school was built that is available to answer any questions and you have a comment of a and so on so you have the better tests they should do the more coverage you have obviously the more extensive the changes that you can make because if you only tested this area can only mess around a little bit more you test the water scope of the changes you can make make a risk assessment and it's something that you can discuss with your clients the risk assessment is basically what I know that things can go wrong but what kind of things can we afford sometimes clients can afford to have the minutes of downtime and that's something to discuss because that means that you can you can maybe be a little more pragmatic and worry that less can they afford to lose data hopefully not but you know talk about these risks and evaluate hominid Sesame to rights and how many changes can afford to make based on the the risk of those actions that you will take it is something to discuss with you might be surprised it might be that it's not really that critical if something breaks for a while you might think it is a new new driver it doesn't but in case it happens you know that you won't get or anything working on the world is is not going to explode we have some clients can stomach Morris and talk to them about that and make a fair assessment and see how much how much he thinks cost this risk always has a cost associated in if the client can pay for that cost then it makes sense so calculated risks so how much to change can be all
intuitive adds once again it depends on the state of the current cold weather things can things are worth salvaging so think of it as and I don't mean to speak ill of the legacy code because it has tremendous value to the clients it got them where they
are maybe they're making millions thanks to that coal-based but think of it as you know a ship that sank ends in or you can solve some parts and some just the bare because there was close or maybe not in line such a bad sense maybe some old computer and maybe you can take some parts out and put on your new computer some question that was challenging it is also more positive metaphor here and I personally always start with the framework and that's really personal because of my experience I tried sometimes to refactor using just smaller components and tying them together but as I was continuing with with the refactoring I always ended up pulling more and more dependencies and in the end they pretty much have framework just bootstrapped in a different way so now I just I was the framework it's those dependencies only cost much usually so just starting something fresh that is complete so that you can quickly build on top of that so a solid foundation onto on top of which you can do even if you're changing small parts because of small parts onto the new framework to worship but yeah start with small changes learned cold and dive deeper as you
learn how the cold worked so make small changes go inside as you are more comfortable with the cold then you can make bigger and bigger changes and as you are making those changes when I said you know what's were salvaging and was worth 3 it rewriting even maybe some things are not that bad and they don't need to be rewritten right now so we give
credit where it's due so if if you look at something like well it's not how I would have written it but it makes sense so I'll just keep it from now because it makes sense I can misses say you have a class and you can interact with it it's not perfect but it does the job and maybe some small changes in the only to make any changes made it works the way it does and you can change everything around it so being the very tolerance and but remember that it was written 15 years ago right so the the practices were not the same we can have the same practices we have now somewhat programming languages that have a of test automation tool well some things like I A C B classic it's like speech 3 it's very very top down here the procedural so is a have basically well when you rewriting eventually you know that if you want to end up with a complete rewrite at some stage because you want everything to be clean you know clean architecture at some point you can say well I'll keep it from now it's like it's like saying you will like you I'll kill you last in it's basically the all so this in in the in about somebody if you if you are going to rewrite it you will but if it makes sense you can keep it for later and his prioritize and how prioritize you start with the components that are the most at-risk in their mathematical models to calculate the rest cyclomatic
complexity and and then you take the ones that are at highest risk and you start refactoring dose or maybe you want to refactor where the client is the most dire the need for example if the system has a lot of components to it and building component is broken and the client cannot build
a customer's properly because that component doesn't do the correct calculations maybe you want to start with that so it is the customer gets the money flowing so we can prioritize differently so when you are at refactoring don't be zealous once again give credit where it's due this is this is not too bad you know you're not worry too much about what indented with times of spaces and you can you can give it a little bits of Due to break basically and I mean like crude it clean cold ends but I still prefer to have a a small footprint when I start changing the cold depends on the on the strategy and if it's a fresh database so if I have to deal with the old database schema but I try to always think about the change in how it contributes toward the objective of the project starts with objectives what are we trying to achieve are we trying to increase the number of sales reduce the number of errors in the billing so once you have those objectives you whenever you make any change thing is it actually contributing to that objective reducing the technical that will probably be 1 of your objectives that's that's the point out to but remember the objective and always make changes that's are contributing the most words that objective any out for their the communities needs migration scripts and the yes because
you're going to need those migration scripts that is why I like to have the smallest footprint possible so that I don't constantly changes schema-consistent things you can you can read down greatly keeping up with the database and
downgrade well if you have deleted the column for example cannot undo meters so there are limitations to them so here some of
my stories of things
that I had to do for my clients
and 1 of them was To magenta is written in PHP it's e-commerce platform as the most popular e-commerce platform and between the minor versions there they were actually very big changes and that not backwards compatible and so on all right there is no other that not backwards compatible but rather that it is very hard to upgrade the database if something something is wrong because they have scripts that can automate this for you which seems like pair just press the button usually how magenta works is you know when you sell plug in of great just dump the new cold in in your directory and Gaussian production which is a bit weird but you don't the new code data and the next time you run any page it's will see that there is a mismatch between the version of the code and you just put in there in the file system because they like XML that says this is the version of the data and so checks against database so here the date is supposed to be 1 . 6 but my database is 1 point 5 so I'm going to execute this and this and this script executes a bunch of SQL and and all that but it but not within the transactions so it's something fails you're stuck with like a half process and you're not sure which plug-ins been migrated so it can be quite difficult it's supposed to be flawless but in this case it wasn't because somebody apparently and made some manual changes to the scheme which made the scripts fail and I don't know which change because some developer sometimes was
higher than did something and only was really something happened to the the production database something of screwed up and and there's no way for me to tell so the simplest way found is to to simulate the upgrade of the clean install and then replicate the changes and by the way if I had a euro for every time I misspelled magenta of living until it wouldn't have been so painful to agree yes and whenever I Google stuff and I misspelled much of those need to
the solution was there to make a fresh 1 . 9 installed I didn't want fresh 1 . 5 in style and then 1 . 9 applied all the same plug-ins that were installed because it's a system that's modular you can download third-party plug-ins putting in directory and all its is supposed to work adjusted of fresh insufferable both and that generated me database schema and now I to those 2 schemas and used a Python script calls schema sink that compares the 2 schemas and generates the SQL necessary to go from 1 and the other and the thing is if you reverse the source and destination it drew the
downgrades patch meeting which is pretty cool and then you take all the content of the database because it's it's Magento stores extra at tributes about entities in a database of this records think if a table called an EV attributes and then basically a product can have extra attributes of the plug-in decided to have and we can use those attributes you don't actually change the database schema you create records in the table so that whenever it tries to fetch attributed goes also checks that table what it contains and then loads from another table by that idea that value of the attribute for that product so and makes things a bit more difficult but once again we can just say that the content of that table and do a depth on the content and you know which ones you will need to port to new system so what I was left with after with a few minor tweaks where I was left with after is a nice SQL script that would have been the database flawlessly because it was designed specifically for that states of the database right even though somebody made some changes that I was aware of this script that that the diff fix that so just think that SQL to the production database and once I had the files installed instead running the agreed great scripts I would run my SQL patch and that's all the problem sometimes you have to be clever and you have to be creative and think outside the box not just worry about how the around those I agreed scripts properly what is it that those scripts doing and then may be replicated in a different manner and they were doing hundreds of queries and so you wouldn't have that
manually but there is a tool that allows me to do that which is pronounced another story is yes that he was actually a mix of speech P3 and PHP 5 but set aside pitch P 5 3 but it wasn't may written for 5 3 and I'm going the call doesn't say what's worse and was written for the server was running
on 5 3 but some of the cold was obviously written in PHP 3 error just by the way it was written by itself because that's how people call that time when you match all of your uh HTML and PHP 1 basis problem in no referencing the objects well that's because speech piece Sweden have object-oriented so that's how I deduce that this is speech P3 3 and somebody tried to do a rewrites with
and some objects in PHP 3 N been complete right and actually make things worse the so we work well worse in the sense that no I have to ways of doing things with a lot of spaghetti and the re write wasn't actually using all key concepts so yes the there are objects but they're not quite oriented anywhere else it's later Joker had a company once a colleague of mine made we said what is object-oriented it's an object might have to just oriented so it basically means that you have a class that doesn't have any properties and you just have a bunch of static methods and that is the same as building the functions that PHP file because static methods without any properties that are objects they're just namespaces for functions and that's only on and there was a lot of that so you would pass always all the arguments to every function instead of instantiating in knowledge having constructors and destructors and doing things properly so was that we just includes over all all over the place and so and those gifts that concatenated SQL CE start with the beginning of an SQL that gets those columns from all manner silly columns none selling right water so it it's of SQL here and there so just strings concatenated together in some some moved away and so I'm not quite sure what was happening there and things that it's 5 that 1 of the 5 that this file includes starts the SQL concatenation work in defines a strain that is later concatenated here so to trace that's I have little it had to take a paper and write the file names and say 0 here's this bit here so I had to like put it together like a puzzle just to understand how is the SQL created and wise it misbehaving why is it not generating the SQL the new so previous
so we rewrites attempt was was a failure and ended up with folders of that cold because not only did the person attempts to rewrite a full we're right up to the person tried to do and then it is quite work so he just to the the folder the he
because I know use so he took the the the folder and what's interesting is that I made assumptions about the person's that the the best personality which were confirmed when when I met him so the colds betrays the prior to the personality behavior it's it's really interesting you can analyze a person's brain by looking at the code the side information so he took this this folder with all of that structure copied next to it and started doing at a different place slightly different approach and then left out all that that cold and things started pointing to 1 folder on the other end is than cold and folders of them but not below which ones sometimes it points to the ones and it's need to it so it was all over the place it was even harder to trace back the original right so the solution to that after
bashing on the other developers concludes at the solution to that was to uh rewrite some of the more complex forms in something which is a well-known framework so the complex forms 1 of the forms that uh was supposed to it is it's a multi for the prior sign a process and so it's stores things in the session and the way was doing storing things would for example you would validated the chance that once Board of that portion validates that to stored at if you go back to Step 1 it will invalidate again because it checks at which stage we were so at stage 2 so we only to Valley stage 1 against the could change things like unchecked the terms of service I disagree to the terms of service and it was so past then you can complete
everything without a graph into the terms which is really weird sigh will all of that in Symphony with proper session management and so that the idea is I re roles also 1 of the biggest module that that the called base had which was the billing module and it was rewritten using proper OOP concepts and in order to rewrite that I use the concept called design extraction which I will mention in a 2nd but uh so I take started the design and then I automated test for that and enabled the code and where did is that for the pages that were concerned by those changes I just put a what we write with the people routed to a different location so I say well for for the sign up enough that once that 2 for the sign of just go to that script instead of the actual file because it was red it was like slash something . php so he was pointing to physical files and so use monetary right to say that file name instead routed to a to routing components in Symphony which would do the rest properly FIL designed
this extraction is an interesting concept the idea
is to avoid called bias
because when you are looking at cold a rewriting of what you are going to write next is going to be influenced by whatever decisions were made in the original code so in order to avoid that into truly create better architecture and truly clean called what you want to stay in the old code and its documentation for that and when I see documentation if they care at here these and flow charts of
decision trees and can share that with the client because clients they understand that if you if you do it in a simple way and you explain to them and the person was totally not a technical person and so I sent him the design documents and we validated decision trees are the simplest ones probably to to talk about so we talk about the decision tree how the billing works it but it makes a decision here and there and about you know based on OK so if it's if the cause of the call originates from this country then add these charges and things like that so I validated that the dead the documents so clarify some of the the business rules as well because I wouldn't have gotten those business rules just by reading the cold the words correctly implemented so I would have made that mistake so in implementing I would have transported all the bugs basically with me for by clarifying now I have I can I we find the documents with the decision to improve the design then I call the customer again
validated changes and we'll do that understand all the business rules correctly yes OK let's move forward and from that design we can then create entirely new called so you don't look at the article you just look at design
documents in you write from scratch and that's where did but just for 1 module of the whole system because it was huge it was written over we have no harm in use but it was just a huge coding so and by improving the design you're making that your in your system more flexible because then you know what kind of of changes the customer might request so you plan ahead for that make more flexible more pluggable and you reduce the technical that dramatically by doing that the and you know when you call your customer of course with their permission you can wreak on the call because it's illegal to require recall without permission just ask is it OK if I recall that and you can then refer to the conversation later and it shouldn't be a conversation that takes more than 1 hour so yes and then we we ruled that component and not runs very well so
some more stories but at that
that is the classic which is pretty much equivalent to preach peace ranges in the wave files a structure in the way people won't very similar and we wanted to move it to PHP 5 6 there was 15 years plus I just made assumptions based on the technology but you could have been older than that so it is the
classic is a longer supported and has really a lot a lot of lines of code said the previous 1 had a lot this 1 I had this zillions of lines of code I don't even know the exact number but it was huge this solution was and show you a diagram of this architecture that proposed is to once again you Symphony my favorite framework is simply to rewrite page by page because the weight is
the classic works is basically just 1 page maybe includes a few files but you enter on a file paths and then you enter in the file and all the HTML is very the title the head title everything Everything is self-contained which is actually easier a bit easier to rewrite and then something that is written with objects because it's it's just so atomic and so what we did is we use more and we write for the constant pages once again to whenever you would try to access and use the File instead would go to the framework and will fetch something entirely different and you think
it's a speed but it's not so it's it's PHP 5 6 now which is now forward compatible with page 7 which is coming out so there there's so and then there was a DB session adapter in both apps because William PHP with simple and and in a speed classic it would a session in some obscure area of bias in the format that will 1st of all it was accessible from PHP and the former the pitch because we need so instead we created inductor luckily there was a file that was being included everywhere that Woods axis that's sessions so we can rewrite so that's that's function to store it in the database instead instead of storing the session somewhere we stored in the database and not PHP can easily access that session I have us share session between the 2 applications and the session is for user login there's many logs and have a session and now they have a convex the customer I. D. and things like that and the thing is the page in any language is just an HTTP requests which is which is what works were advantage we were able to automated with Council by sending an HTTP
request and comparing the output and here's how we how
we set this up so here's the test the guzzled test was that when the test we prepare an HTTP request so you know the upload files or some post just gets you know the URL of the verb and were get still for for DSP applications on all of the verbs used and so we are and we created that they should be request and centered 1st the is the version of the of the page so we will try to to test that age and we got the the response and we cleaned up a bit because some of the HTML was form of that in a weird way that in the parts
were concerned we extracted from in the store that and then we took the same request and sends it to the other version that was not rewritten so we would rewrite literally page by page so you can take one page you can rewrite it in Symphony rear out to it's and I you write the text to said the same request to that page and then compare the responses and if they are the same and a lot of course to check the state such as if the rights to the database you check the stated that these things like that have possibly encapsulated in transactions so that you can roll back without having to redevelop redo the whole database and over time and then we compare the responses and if they are the same then you have succeeded in rewriting it properly of course you're rewriting it's in the clean fashion you know proper and we see and you know separation of concerns of good
patterns and so we we were able to do that literally page by page and it worked really well because now the could stop supporting those other version of the code just delete the old is and no longer have to support it because otherwise and you know they were thinking about other approaches and it would
have been not that nice because you wouldn't be able to you would still have to support to applications at the same time they really wanted that whenever the read at page they want to stop warrior body is p part of that and it was very well another application and this is my last story is of lots and lots of stories that these
just stories from last year and half and by no means complete it's because my my projects my contents are a short sometimes just a few days times maybe maybe a month so the relatively short and so I go through a whole bunch of projects and more than half of them are legacy so please be 3 to PHP 5 6 it was about 12 years old the colds and or you want to speak a lot of taxes usual and that was how we rolled back in the 12 years ago so users use a lot of deprecated functions which made the cold not compatible
with the new were for a bit of PHP 5 6 and we really wanted to leverage some of the newer features like a traits enclosures and just a single short a syntax which is a bit nicer here we're seen how to write a reason PHP when old syntax of speech beats very verbose for no reason and but it's really just a rock and like almost J. like so this so this wouldn't run on page P 5 6 and the version PHP P 5 3 is being discontinued this month so it was essential to use the to me but that's any new called it's written will be written about this thing on page 5 6 and later easily upgradable to uh speech perception so we already know what's coming up in PHP 7 so we can plan ahead and not use the features that they said will be deprecated alright so that the solution for that was actually quite interesting and we splits the service into 5 3 and 5 6 4 effect for
a completely fresh start and so did the NewWave version would be implemented as a recipe Austria diagram moment it's a recipe I and then on the same server where we had the old application we put just a little portion of an angular GS that will then call the new API and languages is named peach peak around so it doesn't matter which version it's on its purely front-end so we we separated like this and then it would called that is running on the new were version and the PI of course is a very good approach and it's would enable them to create better the interface is
better in user experience their workflows and at the same time as I find it personally much easier to deal with the API is then to work with a more complex PHP applications and so it will run on a new entirely new server with speech before I think and that it will be seamless but the only thing we just need to do is for the authorization headers that was coming to the angular applications so whenever you there since you're still in the same domain name the authorization had his will command and you can just wrap the API calls with those authorization headers for them and the the other application would at all of the rights as well so here's here's
set up so the 1st server is not server that come on
1 neuron and then you have a request coming in this is the old application running on 5 3 and then using so in Apache you have interactive called alias which is really nice try and basically the whole some pattern so for example slash modulename whatever follows modulating will be there will be used in a completely different folder which will house the the angle GS application and from aerial send the authorization headers and the PID again I will validate the user still with that so bad this because that's where the users are will validate and but any other requests could make you could add it to this old database new tables but you can also start with a new database it makes no difference not might have this flexibility is a pretty pretty simple things but not not too many components nothing very fancy and it enables to move forward and company won't have any problems with Peachtree version so they will write new modules on this new API and eventually migrate the other
models to that API as well to get rid of speech P 5 3 as fast as possible and when you do that just small parentheses don't forget to implement cost correctly on the side so courses of cross-origin Resource Sharing so that whenever you do AJAX calls the browsers 1st 2 options called for just read up on that but the cool thing with symphonies that it just install bundle it works so it's really nice but if you're not sure how to do this with your application just made up and that this is about sending the proper headers so basically checks with options the options for a sort of posters finding hx with options and as well which had the except which verbs do accept and then and if if those if the 1 that it's trying to say next are not available then it will just not perform that operation Chris is a little extra layer of security right so this is how
alias was set up italy
misses in that contrast is a bit bad and this project but and so the alias was set up you know with a slash module named points to the difference in area in India a different folder on the fastest some and indeed is defined directly with the rewrite basin with the other direct you need them and the slides will be online so you'll have to worry so yeah I hope I will
make it on time yeah I'll try quickly on the next segment the hot to not get stuck
basically start small make a map and don't skip the design stage is very important make a good plan if you're stuck bounce ideas preferably with new people that's are not so on the same people who you regularly talk about technology because everybody tends
to a tunnel vision you know this is the problem you can see everything outside so to be more creative it helps to talk with other people who were not involved in the project so that they can have a fresh perspective on you know and also ask itself has this been done before can I look at some of the cold some examples so this is why I share the stories will this and this has been done before so have some some ideas on how to tackle those problems try another approach you know maybe maybe you're stuck because you're going in direction and you're trying animal to run to PHP versions on the same server while it may be possible but maybe there's another way simply to do that so we broke open your eyes to whatever's around and then see see there's another solutions will talk to people to get those ideas and sometimes it's OK to also walk away sometimes you'll need to change that you're trying to make your so focused on solving this problem that some you realize well maybe I can solve it in an entirely different way so this obstacle will just disappear at will no longer be there because of going in another direction so all this
amounts here I'll just go through each air instead that's the basic idea and ask the refactoring because
there are people who are are specializing in that I 1 students promotion and so pick the brain and you know read the blogs you get high Monday and so for example things that they can do is hope of their refactoring strategies so come up with this diagram these ideas and remove some roadblocks and guidance is something that you can get from from the samples are you can hide them like for 1 day per week that they will come in were in each other the fall and be able to find solutions to common obstacle so that the team isn't you know if they're stuck only step until the next uh check up and then target points the the obstacles might be removed and then we can move forward and not get perpetually stuck in the in the problem of practice creative thinking once again a talk about tunnel vision and opening and to the possibilities of there's a lot of literature and creative thinking it's something that you can you can become more creative do not just 1 creative extendable say it can become more creative by practicing and I myself I went through that change about 2 3 years ago I decided to be more creative so I ran on that's and what some videos and try things and I became a
lot more creative than they used to be which is pretty cool I 1 of the things alone is to step away from the monitor and have a different area where I can think because the monitor is where I have to produce and producing means that you have to focus and that means narrowing your vision instead have wide board area I have been area you something often actually almost every day go for lunch outside and chapter about the problems and that's that really helps and some you can chat with non-developers or just look at how other people in other industries have solved a similar problem may be Gartner has solved the problem that is conceptually the same as yours so you know we read on different things notches development their our asses out there that are just amazing and when you realize that as something that's know some solution that the grocery store found no while this can actually applied to my Michael it's it's amazing what you can find out some some of the
takeaways yet get inspiration from others refactoring is hard at 1st but it gets easier with time with practice if you some known tools and methodologies there there already solutions out there that you can apply and the
practice creative thinking and remember that's not every problem has a solution to the problem 1 on 1 solution and you can just pick them don't don't be afraid don't don't worry that 0 my god there's no solution to this and never gonna get through its things because you're not looking in the right place there's always a solution for that's medium and underdevelopment PHP JavaScript and fix
problems with Biozon performance issues at work provide workshops and testing and angular and API eyes and I help with testing strategy and with legacy code and those slides and we still have 2 2 minutes for questions so so what we so there
is a really all on the right of the the the you in not all my name is you all the patient you are so what I have and how do OK so how cycle things where the database itself is legacy and for example you have a you don't have primary keys on the table so how do you know that I actually had a similar problem recently where database would use a set of our primary keys and we use company keys for that foreign keys for example there's a customer and there some other objects related to the customer so now you have them like a in non not quite unique identifier only unique within the scope of the customer so that's like a compass key and then the object related to that has also so a compass foreign key and then the primary key is accompanied with yet another person might have a 3 key composition and 40 competent as you go down so it was quite a mess and it's not something that was supported by the war and we're using so what we did is we created a proper IDC on those tables and we knew that you we will move forward with that so you can generate so obviously and these things that were there in the past and you can write scripts if you need to link things together and that they can make those changes to the database is satisfactory maybe we can talk about specifics after this right yes and this you it this would did we agreed that this is the and that this is a very tricky to upgrade so if there is is a newer version of the database sometimes they're queries designed for those that the bases will not might not be compatible it's an issue and had to any problems with that amazes go because we can't I guess live With divergence that with them because databases are more limited in features I guess than other programming languages so programming language something you would agree that the base is not US aliki bubble time again the do also gets discontinued versions it can be a challenge but the the hardest part is really I would say not to the schema itself but rather that the SQL queries that are written for that version of N . who might be sometimes the manual process you can you can just grab things In understood the search replace and sometimes you might have to go and manually yeah that can be quite some effort but sometimes that effort might be I might be a good investment when you think about it so maybe take a week to change all those SQL queries but now you agree to a new database which is maybe more featuring rich you can have like you built-in J. some support and things like that can be very useful sigh économiques like relational with no no SQL and questions yeah I think you without
Offene Menge
Softwareentwickler
Software
Freeware
Benutzerbeteiligung
Rechter Winkel
Maschinencode
Vorlesung/Konferenz
Softwareentwickler
Kombinatorische Gruppentheorie
Personal Area Network
Computeranimation
Inklusion <Mathematik>
Facebook
Rahmenproblem
Wort <Informatik>
MySpace
Symboltabelle
Computeranimation
Metropolitan area network
Twitter <Softwareplattform>
Digitalisierer
Web-Designer
Internet Explorer
Vorlesung/Konferenz
Wort <Informatik>
E-Mail
Web Site
Hecke-Operator
Rechter Winkel
Wort <Informatik>
Internet Explorer
Zahlenbereich
Symboltabelle
Default
Computeranimation
Tabelle <Informatik>
Homepage
Internetworking
W3C-Standard
Metropolitan area network
Pixel
Abschattung
Vorlesung/Konferenz
Inhalt <Mathematik>
Extrempunkt
Verzeichnisdienst
Große Vereinheitlichung
Pixel
Computeranimation
Tabelle <Informatik>
Pixel
Momentenproblem
Gemeinsamer Speicher
Maschinensprache
Kombinatorische Gruppentheorie
Computeranimation
Entscheidungstheorie
Objekt <Kategorie>
Flächeninhalt
Mixed Reality
Web-Designer
Vorlesung/Konferenz
Softwareentwickler
Informatik
Touchscreen
Tabelle <Informatik>
Datennetz
Datenhaltung
Formale Sprache
Zellularer Automat
Nabel <Mathematik>
Computeranimation
Dienst <Informatik>
Bereichsschätzung
Flächeninhalt
Datennetz
Mereologie
Vorlesung/Konferenz
Wort <Informatik>
Kantenfärbung
Benutzerprofil
Tabelle <Informatik>
Schnelltaste
Computersicherheit
Formale Sprache
Systemaufruf
Sprachsynthese
Ein-Ausgabe
Komplex <Algebra>
Term
Computeranimation
Mereologie
Vorlesung/Konferenz
Wort <Informatik>
Ordnung <Mathematik>
Gerade
Tabelle <Informatik>
Parametersystem
Befehl <Informatik>
Gewicht <Mathematik>
Ein-Ausgabe
Injektivität
Abfrage
Vorlesung/Konferenz
Wort <Informatik>
Inhalt <Mathematik>
Ein-Ausgabe
Computeranimation
Übergang
Softwaretest
Lineares Funktional
Einfügungsdämpfung
Komponententest
Punkt
Wasserdampftafel
Mathematisierung
Elektronische Publikation
Mathematische Logik
Computeranimation
Weg <Topologie>
Differenzkern
Menge
Loop
Objektorientierte Programmiersprache
Vorlesung/Konferenz
Ordnung <Mathematik>
Inklusion <Mathematik>
Softwareentwickler
Aggregatzustand
Befehl <Informatik>
Flächeninhalt
Softwareschwachstelle
Vorlesung/Konferenz
Ordnung <Mathematik>
Elektronische Publikation
Computeranimation
Verklemmung
Gewicht <Mathematik>
Komponententest
Formale Sprache
Mathematisierung
Klasse <Mathematik>
Automatische Handlungsplanung
Kartesische Koordinaten
Maschinensprache
Computeranimation
Client
Erwartungswert
Maschinencode
Vorlesung/Konferenz
Maßerweiterung
Gerade
Softwaretest
Assoziativgesetz
Zentrische Streckung
Termersetzungssystem
Datenhaltung
Güte der Anpassung
Klassische Physik
Systemaufruf
Schlussregel
Bitrate
Modul
Portscanner
Verkettung <Informatik>
Flächeninhalt
Rechter Winkel
Mereologie
Wort <Informatik>
Varietät <Mathematik>
Zeichenkette
Programmiersprache
Einfach zusammenhängender Raum
Subtraktion
Verklemmung
Datenhaltung
Formale Sprache
Versionsverwaltung
Sprachsynthese
Kartesische Koordinaten
Elektronische Publikation
Computeranimation
Portscanner
Virtuelle Maschine
Maschinencode
Lesen <Datenverarbeitung>
Leistung <Physik>
Bit
Komponententest
Kontrollstruktur
Stab
Wasserdampftafel
Mathematisierung
Gruppenoperation
Maschinensprache
Datensicherung
Datensicherung
Computeranimation
Client
Softwaretest
Migration <Informatik>
Kontrollstruktur
Skript <Programm>
Dateiverwaltung
Analytische Fortsetzung
Leistung <Physik>
Leistungsbewertung
Softwaretest
Datenhaltung
Schlussregel
Programmierumgebung
Physikalisches System
Rechnen
Biprodukt
Portscanner
Patch <Software>
Druckertreiber
Menge
Flächeninhalt
Rechter Winkel
Gamecontroller
Programmierumgebung
Stereometrie
Mathematisierung
Strömungsrichtung
Maschinensprache
Computer
Framework <Informatik>
Computeranimation
Client
Surjektivität
Maschinencode
Mereologie
Zusammenhängender Graph
Refactoring
Gerade
Aggregatzustand
Softwaretest
Punkt
Prozess <Informatik>
Maschinencode
Mathematische Modellierung
Formale Sprache
Klasse <Mathematik>
Mathematisierung
Klassische Physik
Sprachsynthese
Zusammenhängender Graph
Computerarchitektur
Computeranimation
Punkt
Datenhaltung
Mathematisierung
Gebäude <Mathematik>
Mathematisierung
Zahlenbereich
Physikalisches System
Migration <Informatik>
Rechnen
Raum-Zeit
Computeranimation
Eins
Objekt <Kategorie>
Client
Migration <Informatik>
Strategisches Spiel
Skript <Programm>
Skript <Programm>
Projektive Ebene
Zusammenhängender Graph
Fehlermeldung
Punkt
Prozess <Physik>
Datenhaltung
Mathematisierung
Versionsverwaltung
Mathematisierung
Nummerung
Maschinensprache
Migration <Informatik>
Biprodukt
Systemplattform
Computeranimation
Homepage
Transaktionsverwaltung
Client
Migration <Informatik>
Meter
Dateiverwaltung
Skript <Programm>
Inverser Limes
Vorlesung/Konferenz
Skript <Programm>
Softwareentwickler
Verzeichnisdienst
Datenhaltung
Skript <Programm>
Plug in
Patch <Software>
Quellcode
Physikalisches System
Biprodukt
Verzeichnisdienst
Gerichteter Graph
Computeranimation
Subtraktion
Bit
Quader
Mathematisierung
Sprachsynthese
Patch <Software>
Computeranimation
Eins
Datensatz
Maschinencode
Mixed Reality
Skript <Programm>
Skript <Programm>
Inhalt <Mathematik>
Speicher <Informatik>
Attributierte Grammatik
Datenhaltung
Abfrage
Systemaufruf
Physikalisches System
Biprodukt
Elektronische Publikation
Patch <Software>
Verbandstheorie
Rechter Winkel
Last
Server
Tabelle <Informatik>
Aggregatzustand
Konstruktor <Informatik>
Lineares Funktional
Parametersystem
Bit
Namensraum
Kategorie <Mathematik>
Wasserdampftafel
Klasse <Mathematik>
Schreiben <Datenverarbeitung>
Sprachsynthese
Elektronische Publikation
Computeranimation
Data Mining
Objekt <Kategorie>
Hydrostatik
Rechter Winkel
Maschinencode
Basisvektor
Zeichenkette
Fehlermeldung
Rechter Winkel
Maschinencode
Information
Maschinensprache
Datenstruktur
Computeranimation
Eins
Prozess <Physik>
Mathematisierung
Maschinensprache
Komplex <Algebra>
Term
Framework <Informatik>
Computeranimation
Homepage
Multiplikation
Bildschirmmaske
Softwaretest
Datenmanagement
Vorzeichen <Mathematik>
Skript <Programm>
Zusammenhängender Graph
Softwareentwickler
Speicher <Informatik>
Modul
Softwaretest
Graph
Elektronische Publikation
Modul
Bildschirmmaske
Dienst <Informatik>
Loop
Rechter Winkel
URL
Eigentliche Abbildung
Ordnung <Mathematik>
Physikalischer Effekt
Programmablaufplan
Systemaufruf
Schlussregel
Maschinensprache
Computeranimation
Entscheidungstheorie
Programmfehler
Eins
Netzwerktopologie
Client
Zustandsdichte
Maschinencode
Vorlesung/Konferenz
Wort <Informatik>
Computerarchitektur
Ordnung <Mathematik>
Umsetzung <Informatik>
Dämpfung
Zustandsdichte
Maschinencode
Mathematisierung
Systemaufruf
Zusammenhängender Graph
Schlussregel
Physikalisches System
Maschinensprache
Modul
Computeranimation
Gewicht <Mathematik>
Termersetzungssystem
Wellenlehre
Zahlenbereich
Maschinensprache
Framework <Informatik>
Computeranimation
Homepage
OISC
Spannweite <Stochastik>
Diagramm
Zustandsdichte
Maschinencode
Computerarchitektur
Datenstruktur
Gerade
App <Programm>
Bit
Datenhaltung
Formale Sprache
Konvexer Körper
Kartesische Koordinaten
Elektronische Publikation
Login
Framework <Informatik>
Computeranimation
Homepage
Homepage
Objekt <Kategorie>
Softwaretest
Flächeninhalt
Dateiformat
Schreib-Lese-Kopf
Softwaretest
Trennungsaxiom
Bit
Abstrakter Syntaxbaum
Datenhaltung
Güte der Anpassung
Versionsverwaltung
Kartesische Koordinaten
Elektronische Publikation
Computeranimation
Homepage
Homepage
Axiom
Metropolitan area network
Bildschirmmaske
Softwaretest
Rechter Winkel
Endogene Variable
Mereologie
Vorlesung/Konferenz
URL
Speicher <Informatik>
Funktion <Mathematik>
Lineares Funktional
Abstrakter Syntaxbaum
Vervollständigung <Mathematik>
Versionsverwaltung
Kartesische Koordinaten
Maschinensprache
Computeranimation
Homepage
Axiom
Arithmetisches Mittel
Metropolitan area network
Softwaretest
Mereologie
Projektive Ebene
Inhalt <Mathematik>
Lesen <Datenverarbeitung>
Server
Bit
Momentenproblem
Formale Sprache
Güte der Anpassung
Versionsverwaltung
Sprachsynthese
Kartesische Koordinaten
Systemaufruf
Computeranimation
Homepage
Dienst <Informatik>
Diagramm
Schwebung
Front-End <Software>
Server
Schnittstelle
Autorisierung
Server
Kartesische Koordinaten
Sprachsynthese
Komplex <Algebra>
Systemaufruf
Computeranimation
Metropolitan area network
Domain-Name
Rechter Winkel
Front-End <Software>
Server
E-Mail
Modul
Aliasing
Subtraktion
Browser
Versionsverwaltung
Kartesische Koordinaten
Sprachsynthese
Computeranimation
Metropolitan area network
Informationsmodellierung
Hauptidealring
Mustersprache
Vorlesung/Konferenz
Zusammenhängender Graph
E-Mail
Modul
Autorisierung
Nichtlinearer Operator
Datenhaltung
Winkel
Computersicherheit
Modul
Quick-Sort
Konfiguration <Informatik>
Rechter Winkel
Faserbündel
Tabelle <Informatik>
Aliasing
Subtraktion
Punkt
Güte der Anpassung
Automatische Handlungsplanung
Mathematisierung
Varianz
Oval
Aliasing
Modul
Computeranimation
Rechenschieber
Flächeninhalt
Vorlesung/Konferenz
Maschinelles Sehen
Kontrast <Statistik>
Ideal <Mathematik>
Perspektive
Server
Versionsverwaltung
Mathematisierung
Maschinelles Sehen
Oval
Ideal <Mathematik>
Maschinelles Sehen
Computeranimation
Richtung
Web log
Mathematisierung
t-Test
Whiteboard
Computeranimation
Web log
Videokonferenz
Arithmetisches Mittel
Diagramm
Flächeninhalt
Offene Menge
Stichprobenumfang
Strategisches Spiel
Softwareentwickler
Speicher <Informatik>
Refactoring
Maschinelles Sehen
Rechenschieber
Softwaretest
Maschinencode
Grundsätze ordnungsmäßiger Datenverarbeitung
Strategisches Spiel
Maschinensprache
Computeranimation
Umwandlungsenthalpie
Programmiersprache
Offene Menge
Prozess <Physik>
Zirkel <Instrument>
Datenhaltung
Mathematisierung
Relativitätstheorie
Formale Sprache
Versionsverwaltung
Abfrage
Computeranimation
Objekt <Kategorie>
Freeware
Software
Menge
Rechter Winkel
Mereologie
Dreiecksfreier Graph
Skript <Programm>
Stützpunkt <Mathematik>
Vorlesung/Konferenz
Identifizierbarkeit
Schlüsselverwaltung
Tabelle <Informatik>

Metadaten

Formale Metadaten

Titel Rewriting 12-Year-Old Code
Serientitel FrOSCon 2015
Teil 79
Anzahl der Teile 80
Autor Filina, Anna
Lizenz CC-Namensnennung 3.0 Unported:
Sie dürfen das Werk bzw. den Inhalt zu jedem legalen Zweck nutzen, verändern und in unveränderter oder veränderter Form vervielfältigen, verbreiten und öffentlich zugänglich machen, sofern Sie den Namen des Autors/Rechteinhabers in der von ihm festgelegten Weise nennen.
DOI 10.5446/19551
Herausgeber Free and Open Source software Conference (FrOSCon) e.V.
Erscheinungsjahr 2015
Sprache Englisch

Inhaltliche Metadaten

Fachgebiet Informatik
Abstract Did you ever have to maintain a 12-year-old application? Dead code and tables everywhere, static methods, database queries in between HTML tags and some pages still in PHP3. This presentation will lead you through a progressive rewrite from very old legacy to the latest shiny version of PHP. Learn how to automate legacy testing, how to seamlessly jump between the old and new parts, and how to overcome other challenges that arise from dealing with a codebase that was written in 2003. Anna Filina

Ähnliche Filme

Loading...