Stuart Breckenridge

The Influence of Facebook

Rory Cellan-Jones, for the BBC:

In the United States, newspapers take their responsibilities to the democratic process very seriously.

So seriously, in fact, that they can come across as rather pompous to a British reader. When it comes to a presidential election they seem to believe that their endorsements are of huge significance and that their words will be weighed with utmost seriousness by their readers.

Now both the newspapers and the rest of the mainstream media are waking up to the fact that their influence may be as nothing compared with that of Facebook.

The News Feed algorithm serves you up whatever it thinks you and your friends want to believe and it certainly does not do any fact-checking.

Stories that accused the Clintons of murder or maintained that Barack Obama was a Muslim will have cropped up in the feeds of millions of people inclined to support Mr Trump.

Firing human editors really worked out well.


Fascism: I Sometimes Fear...

Michael Rosen on Fascism (link):

I sometimes fear that
people think that fascism arrives in fancy dress
worn by grotesques and monsters
as played out in endless re-runs of the Nazis.

Fascism arrives as your friend.
It will restore your honour,
make you feel proud,
protect your house,
give you a job,
clean up the neighbourhood,
remind you of how great you once were,
clear out the venal and the corrupt,
remove anything you feel is unlike you…

It doesn’t walk in saying,
“Our programme means militias, mass imprisonments, transportations, war and persecution.”


Reversing Progress

Peter Baker, for the New York Times:

For the first time since before World War II, Americans chose a president who promised to reverse the internationalism practiced by predecessors of both parties and to build walls both physical and metaphorical. Mr. Trump’s win foreshadowed an America more focused on its own affairs while leaving the world to take care of itself.


Completion Handlers vs. Delegation with URLSession

I am currently working on a URL shortener side project that uses URLSession and it just so happens that over on Use Your Loaf Keith Harrison was examining the same problem as me: completion handlers or delegation.

My initial API for shortening URLs used a completion handler:

public func shortenURL(url:String, completionHandler:@escaping (Bool, String?) -> ()) throws {
	// Setup Code  //
	let session = URLSession(configuration: .default, delegate: nil, delegateQueue: nil)
	let task = session.dataTask(with: urlComponents.url!, completionHandler: {(data, response, error) in
            if data != nil && error == nil {
                do {
                    let json = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.allowFragments) as! NSDictionary
                    
                    guard let shortenedURL = json["shorturl"] as? String else {
                        completionHandler(false, nil)
                        return
                    }
                    
                    completionHandler(true, shortenedURL)
                } catch {
                    completionHandler(false, error.localizedDescription)
                }
            }
        })
    task.resume()
}

This worked fine, but I still prefer to use delegation when using URLSession:

public func shortenURL(url:String) throws {
	// Request did begin
	self.delegate?.didBeginRequest()
	
	// Setup Code //
	
	let session = URLSession(configuration: .default, delegate: nil, delegateQueue: nil)
        let task = session.dataTask(with: urlComponents.url!, completionHandler: {(data, response, error) in
            if data != nil && error == nil {
                do {
                    let json = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.allowFragments) as! NSDictionary
                    
                    guard let shortenedURL = json["shorturl"] as? String else {
                        DispatchQueue.main.async {
                            self.delegate?.didFailWith(error: nil)
                        }
                        return
                    }
                    
                    DispatchQueue.main.async {
                        self.delegate?.didShortenTo(url: shortenedURL)
                    }
                } catch {
                    DispatchQueue.main.async {
                        self.delegate?.didFailWith(error: error)
                    }
                }
            }
        })
    task.resume()
}

Why delegation? URLSession doesn’t have a didBeginRequest() equivalent and I like having that granular level of control.