Research and reports
In this post I describe a neat but simple trick that you can use to help inform developers of proposed architectural direction changes in the code they are modifying.
This is especially useful on a large, constantly evolving monolithic code base where refactors may take time and require a concerted effort across the whole team.
An example illustrates the concept quite nicely:
bundle exec rspec spec/features/deprecated_classes_spec.rb
This is a great call to action.
It encourages teams to have a conversation about the desired approach, read the docs, and collaborate where required. This may be the time to upgrade this part of the system or it maybe just fine to update the sha and carry on, assuming the relevant parties have agreed so. This change also has the benefit of showing up in a pull request and so any changes may need to be justified.
In summary, it provides an opportunity to constantly improve and share the knowledge. One of our principles at Simply Business is "maintenance is a must" and this certainly embraces that.
Feature: Deprecated classes
As a developer I want to raise awareness of deprecated classes So that we don't build on code we want to refactor when we next modify it And therefore we "do it right"
Scenario: Modifying a class which is marked as deprecated due to the new support framework Given a list of deprecated files | file | sha | | app/support/book.rb | f92f8a | | app/support/page.rb | fbb220 |
This test fails because you have made a change to one or more files which we would like to deprecate in favour of our preferred design approach.
Please consult with the guidelines here http://example.com/refactor or talk to the 'Acme' group within the company for guidance. """ When any of the files is detected as being modified Then this test will fail with a deprecation message`
step "a list of deprecated files" do | files | @files = files.to_h @files.delete('file') end
step "a deprecation message:" do | msg | @msg = msg end
step "any of the files is detected as being modified" do @expected = @files.keys.each_with_object() do | filename, current_shas | contents = File.read(File.expand_path(File.join (dir,'..','..',filename))) current_shas[filename] = Digest::SHA1.hexdigest(contents) end end
step "this test will fail with a deprecation message" do expect( @expected ).to match( @files ), @msg end
You can view the full source for the example on the Github repository.
Want to know more about what it's like to work in tech at Simply Business? Read about our approach to tech, then check out our current vacancies.Find out more
We create this content for general information purposes and it should not be taken as advice. Always take professional advice. Read our full disclaimer
6th Floor99 Gresham StreetLondonEC2V 7NG
Sol House29 St Katherine's StreetNorthamptonNN1 2QZ
© Copyright 2023 Simply Business. All Rights Reserved. Simply Business is a trading name of Xbridge Limited which is authorised and regulated by the Financial Conduct Authority (Financial Services Registration No: 313348). Xbridge Limited (No: 3967717) has its registered office at 6th Floor, 99 Gresham Street, London, EC2V 7NG.