GMA News Online:

The Manila city government will deploy a drone as its eye in the sky over the Manila North Cemetery, Metro Manila’s biggest cemetery, during the Undas (All Saints’ and All Souls’ Days) weekend.

City government officials expect the drone to help them spot brewing or potential trouble, radio dzBB’s Carlo Mateo reported Friday.

This is great, kudos to Manila city government for coming up with the idea. Not only it has a good chance to solve crowd-monitoring problem, it is also a potentially transferrable solution for events including calamities. The only thing I worry is the drone’s battery life. It typically lasts up to 30 minutes only.

 

Facebook open-sourced osquery:

Osquery exposes an operating system as a high-performance relational database. This design allows you to write SQL-based queries efficiently and easily to explore operating systems. With osquery, SQL tables represent the current state of operating system attributes, such as:

  • running processes
  • loaded kernel modules
  • open network connections

SQL tables are implemented via an easily extendable API. Several tables already exist and more are being written. To best understand the expressiveness that is afforded to you by osquery, consider the following examples.

Other than the deliberately lower-cased name, impressive.

 

Smart started accepting iPhone 6/6+ pre-registration yesterday, a day later from Globe’s.

A small but noticeable difference between the two registration pages is the inclusion of type of application on Smart’s pre-registration page. My fingers are crossed hoping that existing subscribers has edge over new ones.   Of course, it could easily mean the other way around — Smart filtering and favoring new applications.

LTFRB apprehending an Uber-associated vehicle:

Ang problema natin diyan, vehicles are not registered with the LTFRB or any agency under the DOTC (Department of Transportation and Communications),” Cabrera told TV5. “The truth is napakarami na naming complaints na natanggap.

I’m all for innovation. However, with the risk of stating the obvious, innovation should operate within the limits of the law. The transportation industry is a regulated industry. The governing laws protect not only the commuting populace, but every party involved. Whether these laws are executed properly or not isn’t enough for the tech industry to exploit and call it innovation.

An important part of solving this problem is to find an acceptable solution that includes drivers and operators. Uber should do better.

UPDATE 1: MMDA disagrees with LTFRB:

“The muscle of the law and the procedural and technical arms of government agencies alone cannot solve the lack of alternative means of transportation. They can only increase apprehension records. Uber or hybrid carpooling is a well-meaning technology-driven effort intended for public safety and convenience. That’s why people are patronizing it,” said MMDA Chair Francis Tolentino.

I interpret this statement as a plea to LTFRB to keep an open mind about Uber. I fully agree. LTFRB should do everything it can to help companies like Uber create an alternative solution to the worsening traffic problem in Metro Manila within the limits of the law.

This is also a direct admission of Tolentino that LTFRB is right for apprehending the Uber-commissioned SUV.

UPDATE 2: Yugatech defends LTFRB.

Uber has faced exactly the same regulatory issues in other countries in Europe, South Korea and even in its home country in the United States. So it’s not just the LTFRB who has an issue with Uber.

Compared to other taxi apps like GrabTaxi or EasyTaxi where the vehicles have legitimate operators and franchise holders, Uber does not have the same license to operate a fleet. If they applied for a franchise, permit or something similar, and is granted one, then there should not be any problem.

Yet netizens are furious.

Martin Fowler:

But often the best code you can write now is code you’ll discard in a couple of years time.

Provocative yet brilliant. Furthermore:

But often in the early period of a software system you’re less sure of what it really needs to do, so it’s important to put more focus on flexibility for changing features rather than performance or availability. Later on you need to switch priorities as you get more users, but getting too many users on an unperforment code base is usually the better problem than its inverse.

This is tangential from the original post but this reminds me of most developers’ mindset towards application development: a list of features to be implemented rather than a problem to be solved. Often, we assume that software is defined from the get go. This couldn’t be further from reality.

 

 

The Verge caught this little nugget on Yosemite:

You can remotely activate the personal hotspot feature on the iPhone and use it to connect your Mac to the internet…

I could honestly say that this is the feature that I appreciate the most. Connecting your Mac to your iPhone’s hotspot pre-iOS 8 was tricky to borderline annoying: if you miss the time window, the phone connects to a wifi forcing you to restart the whole process.

MVC controllers are not very reusable. You cannot reuse codes from one controller to another (technically, you can but it’s ridiculous). This often leads to developers being sloppy and doing everything inside a controller. I have witnessed unending horror of controllers so heavily coded that I was hesitant to add another line of code worrying that it might blow right in front of me.

Fat Controllers

Consider saving a product category, let’s say you put it in a ProductCategory controller, under the Save action. This looks fine and harmless. However, let’s say you want to implement an import product feature that requires all product categories in a CSV to be automatically created if not found. You will end up duplicating the code for saving a product category.

A more sophisticated example would be the import CSV feature itself. Let’s say you implemented it in Product controller. Then it needs to be implemented on another controller, say Employee. This results to multiple versions of the CSV import which not only leads to buggy application but also to a testing predicament. Imagine hundreds of situations like this scattered all over your controllers.

Obese Models

Before I get into obese models, let me define what a model is: model is a layer not an object. This has been repeatedly said on many StackOverflow answers and it’s worth reiterating again. Often, developers confuse Data Transfer Objects (DTOs) as their Model (or even ViewModel — the whole DTO vs ViewModel vs Model is a lengthy, not to mention touchy topic so I’m not going to touch it with a ten-foot pole). I don’t blame developers here as even on Microsoft’s website, Model is defined as “objects”. This definition is not incorrect but rather limited.

A popular way to reduce controller bloat is to fatten the model instead: shoving business logics to models. While this solves the code reuse problem, it introduces another problem: fat model too often causes overlaps blurring the main purpose of the class. This happens when you need to process multiple entities, you are forced to do it in one model which results to god objects – unwieldy, monolithic models that are difficult to maintain. The problem stems from the fact that you abstracted the problem using the model instead of what problem actually constitutes. Take the import CSV example above. Using fat model, it’s almost deliberately telling you to create an Import method under your product model (if you’re importing products) even it’s obvious that the concern is potentially beyond products.

Fat Controllers – Service layer = Lean Models

Using a service layer compliments thin controllers and lean models. It is a set of classes that serves as a front-line of your model layer. The controller simply talks to the service layer, hiding all the intricacies of your data layer from controller at the same time fully encapsulates the domain. Consider the this action from a controller:

[HttpPost]
public JsonResult ImportProducts(IEnumerable files) {
    return Json(new ImportCSVHelper<Product, IProductRepository>()
                        .Import(a => new Product {
                            Active                 = true,
                            Barcode                = a[1],
                            Color                  = a[2],
                            DaysForReplacement     = Convert.ToInt32(a[3]),
                            Discount               = Convert.ToInt32(a[4]),
                            IsReordered            = Convert.ToBoolean(a[5]),
                            ItemCategoryId         = new ProductCategoryHelper().GetCategoryId(a[6], true),
                            ItemCode               = a[7],
                            UnitOfMeasurementId    = new UnitOfMeasurementHelper().GetUnitOfMeasurement(a[8], true)
                            //More field mappings here...
                }, files.First()), JsonRequestBehavior.AllowGet);
}

There are few main things that I let my controller handle: return and/or route a view, populate the view model, and call codes from the service layer. Codes that do not fall on any of these categories are typically moved out. In the example above, I let the calling code in the controller define the mapping of the properties to the CSV fields. This way, my service class does not care how the mapping happens, it ‘s just concern is how to save the entities to the database.

public class ImportCSVHelper <T, TR> where T    : BaseModel, new()
                                     where TR   : IBaseRepository   {
 
        public Tuple<int, int> Import(Func<string[], T> method, HttpPostedFileBase file) {
            //Initialisation stuff
 
            file.SaveAs(path);
            File.ReadLines(path)
                .ToList()
                .ForEach(a => {
                    T t;
                    try {
 
                        var fields = a.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        t = CreateType(method, fields);
 
                        _repository.Add(t);
                        totalSuccess++;
 
                    } catch {
                        totalFailed++;
                    }
                });
 
            _repository.Save();
            return new Tuple<int, int>(totalSuccess, totalFailed);
        }
 
    }
}

Service classes must be very flexible. In the example above, the ImportCSVHelper class accepts two generic parameters: the type we want to import and a repository interface. This might be a little too far but it perfectly illustrates the point I am trying to make: I can use the class to import CSV on any entity, on any controller. This pattern allows ultimate code reuse and eliminates the fat on both controllers and models by distributing the codes to its correct domain.

Techolo reading through the fine print of Smart’s recently announced free internet promo:

So what is the scope of this free internet? This is applicable to all active prepaid subscribers. It will be free for up to 30MB and still subject to promo terms and fair use. Active users are those who have at least one peso load or is subscribed to any load bucket or promo.

Of course, with everything free, comes some fine print. These are the type of websites excluded from the promo:

  • Download, stream and watch videos (Youtube, Vimeo)
  • Use VOIP apps (FaceTime, FaceTime Audio, Skype, Viber, Tango)
  • Use messaging apps (Whatsapp, WeChat, Line, Viber)
  • Peer-to-peer file-sharing sites and apps like Bittorrent

These caveats are expected. However, the exclusion of messaging apps seems weird to me. They are allowing photo upload (here’s a cached, text-only version of the announcement. For some reason, the actual page is not showing up on me) so why not messaging? If they are trying to “stimulate the internet habit”, messaging apps would be one of the best way to convey the message.