Medium Engineering

Stories from the team building Medium.

Follow publication

How the Medium iOS team works effectively with legacy code

Zouhair Mahieddine
Medium Engineering
Published in
11 min readJul 29, 2024

By Ed Uthman — originally posted to Flickr as Apple I Computer, CC BY-SA 2.0, https://commons.wikimedia.org/w/index.php?curid=7180001

Working effectively with legacy code

Changing software

I don’t have much time and I have to change it

Story page header and footer
New “More from this list” recommendation carousel in the story page footer

I don’t understand the code well enough to change it

The Medium iOS app dark mode support prior to iOS official support
The Medium iOS app dark mode support after iOS official support
The Medium iOS app dark mode support today

My application has no structure

This class is too big and I don’t want it to get any bigger

Push notifications subscription settings screen in the Medium iOS app

How do I know that I’m not breaking anything?

// Async method returning a promise
- (KSPromise *)deferSomeWork {
KSDeferred *deferred = [KSDeferred defer];
// do some work, potentially return a deferred error.
return deferred.promise;
}

// Caller expecting a promise
- (void)someOtherMethod {
[[self deferSomeWork] then:^id(id value) {
// Everything went well, read the value and continue
} error:^id(NSError *error) {
// Handle deferred error
}];
}
// New async method using a completion block
- (void)deferSomeWorkThen:(void (^)(id value))thenCallback
error:(void (^)(NSError *error))errorCallback {
// do some work
if (someError != nil) {
errorCallback(error);
} else {
thenCallback(someValue);
}
}
// Caller, now without promise
- (void)someOtherMethod {
[self deferSomeWorkThen:^id(id value) {
// Everything went well, read the value and continue
} error:^id(NSError *error) {
// Handle error
}];
}

To rewrite or not to rewrite

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Written by Zouhair Mahieddine

Software engineer @Medium. Read more about what I do at Medium here: https://medium.com/p/8b6090f4508e. Also, take a look at my blog https://www.zedenem.com.

Responses (15)

Write a response