• 开源镜像
  • 开源沙龙
  • 媛宝
  • 猿帅
  • 注册
  • 登录
  • 息壤开源生活方式平台
  • 加入我们

开源日报

  • 2018年10月3日:开源日报第209期

    3 10 月, 2018

    每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,欢迎关注开源日报。交流QQ群:202790710;微博:https://weibo.com/openingsource;电报群 https://t.me/OpeningSourceOrg


    今日推荐开源项目:《macOS 的微信插件 WeChatPlugin-MacOS》传送门:GitHub链接

    推荐理由:顾名思义,这个插件可以增强 macOS 上微信上的功能,例如防撤回,自动回复等等。这个插件应该很适合在使用 macOS 版微信的朋友,如果不玩微信使用 QQ 的话他们也有加强 QQ 功能的插件,有兴趣的话可以自己下一个玩玩。


    今日推荐英文原文:《Building your own Design Pattern》作者:Abhishek Kharb

    原文链接:https://medium.com/@abhishek.kharb30/building-your-own-design-pattern-5f30b7d16122

    推荐理由:这篇文章介绍了设计模式,包括 MVC 和 MVVM 以及它们的不足之处等等

    Building your own Design Pattern

    Ever so often, developers face the dilemma of choosing from multiple design patterns for their code. Yes, there are deadlines to adhere to, there are changing needs of the product, the code needs to be testable and what not! But as a developer, you always want to write code that’s scalable, modular and easy to debug for any issues, if not bug-free now — not an easy task by any means! You have to be very smart in locking down the foundation for your code. After all, it’s only on a strong foundation, that you can build a scalable structure.

    What you’ll learn in this post:

    • What MVC, MVVM etc. are all about and some of their shortcomings
    • Why design patterns are an important part of development lifecycle
    • How you can alter some of the aspects of these patterns to come up with your own version, as per your use case
    • How we design high quality, stable features at Hike using our Hybrid design pattern

    MVC

    The standard MVC pattern has three major components:

    Model — The Model is usually the data source of the system. It interacts with the controller to provide the current state of your database. Data can reside locally in your system, or fetched from the servers. In any case, the model provides you with the relevant information.

    View — View is what you see on your screen. All the UI components together constitute the view. In standard MVC implementations, views are usually pretty dumb with no business logic to them. They get directions from the controller and populate themselves accordingly. Similarly, any actions that the user takes on the UI are passed on to the controller to handle.

    Controller — This is where all the action happens! The Controller takes care of multiple things. Firstly, it instantiates both the Model and the View components. All business logic in response to user actions, asking the model to update itself, and listening to any changes in the model that might need refreshing the view happens in the controller!

    A typical MVC interaction system

    Few details of MVC:

    • The Model and the View only interact with the controller, and NEVER talk to each other directly. All communication happens via the Controller only.
    • As a result, the Controller usually becomes one massive class, handling multiple responsibilities.
    • All components are tightly coupled with each other. This makes reusability of these components difficult, replacing any of them later on, or making changes to them is a tough ask!
    • Writing tests and debugging intricate bugs in one massive controller class can be tricky.

    MVVM

    The following components form the main aspect of this pattern:

    Model — The Model in MVVM works similar to MVC. It gives you the data you need, which can be present locally, or fetched from servers behind the scenes, just like in MVC.

    View — Implemented as a View/View Controller subclass, the view here talks to the view model to gather all information, that is needed to display all UI components.

    View Model — This is the major differentiating component from a MVC. The view model acts as the intermediate between the view and the model. Unlike MVC, the model is owned by View Model.

    MVVM interaction system

    Few details of MVVM:

    • The view here is a UIKit independent implementation. The view controller itself can be treated as the view component.
    • There’s complete isolation of the Model and the View, which makes them loosely coupled with one another.
    • The View Model invokes all changes to the model and listens to any changes that the Model makes behind the scenes.
    • The View and View Model interact via bindings, so any change in the Model notifies the View Model, which in turn updates the View.
    • This clearly helps break the massive controller of MVC, with the View and View Model now sharing responsibilities of updating UI and the coordination between components, respectively.

    Discussion:

    As we saw earlier, while MVC works for small contained components, it fails to meet the requirements of an evolving and growing product. Adding new code to an MVC system is difficult without breaking existing parts. Debugging issues in an MVC system can be time consuming, and sometimes can lead you clueless, as your controller is taking care of a million things at the same time.

    While MVVM was great in taking care of some of those concerns, we thought there was still scope for some more modularity, some more scalability. We could do better! We could break these components into further subcomponents. The idea was to evolve the architecture in such a way that more and more components became reusable. It should be easier to replace one component without affecting the whole system.

    So we went through these and a few more design patterns like VIPER, RIBs, evaluated their advantages/disadvantages, and compared them with our use case. We went through the common limiting factors encountered while scaling our systems. The final pattern we came up with was a hybrid version of the MVC and MVVM patterns.

    Hybrid MVC and MVVM pattern

    The following diagram shows the various components and their interaction within this pattern:

    Let’s go over the functionalities of each of these:

    • Data Source — The Data Source is responsible for providing data to the entire system. This can be any generic class conforming to a protocol that is used by the Controller to ask for data. The data can be stored internally in any way. All that detail is internal to the implementation of Data Source. Conforming to a protocol ensures that we can replace the data source implementation without affecting any other component. All we need is for the new class to conform to the data source protocol, and we won’t have to change any other aspect. Given the Controller owns the Data Source, any changes in the underlying data are conveyed to the Controller that can then initiate appropriate action for it.
    • Controller — The controller is at the centre of it all though much of its responsibility is to coordinate other items to enable them to function together. Usually this is a View Controller subclass, which is initialised with a Data Source object. Suppose we have to implement a chat screen, which shows all messages and has ability to send messages. The main chat view controller will act as the Controller. The table view to show all messages would be a part of the chat view controller. The initialisation would look something like this:
    - (void)showChatViewController {
      HikeChatDataSource *dataSource = [[HikeChatDataSource alloc] initWithStoreType:HikeChatDataStoreTypeCoreData 
                                                                            chatId:chatId
                                                                          chatType:HikeChatTypeDefult];
      HikeChatViewController *chatViewController = [[HikeChatViewController alloc] initWithDataSource:dataSource];
      [self pushViewController:chatViewController animated:YES];
    }
    Controller Initialisation
    • View — The independent UI components can be separated out in a separate View layer. The Controller instantiates and holds references to them.The View is passed as a View Model object that the View uses to populate itself. In case of our example, the cells of the table View can be initiated with this pattern, where we pass them a View model object to populate with:
    - (id<HikeChatCellItemProtocol>)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      id <HikeChatCellModelProtocol> modelObject = [self.dataSource modelObjectForCellAtIndexPath:indexPath];
      id <HikeChatCellViewModelProtocol> viewModel = [self viewModelForModelObject:modelObject];
      id<HikeChatCellItemProtocol> cell = [tableView dequeueReusableCellWithIdentifier:[self cellIdentifierForViewModel:viewModel] forIndexPath:indexPath];
      [cell populateWithViewModel:viewModel];
      return cell;
    }
    View Initialisation
    • View Model — The View Model is instantiated by the Controller for the independent View components that need not be part of the Controller class. Identifying such View-View Model components can help keep your Controller light and code modular. The View Model is initialised with a Model object that contains all information needed by the view to populate itself. The other important aspect to it is that we don’t expose class names anywhere, we only expose id<some_protocol> type of objects. This makes it easier to replace these components without affecting any other components:
    + (id <HikeChatCellViewModelProtocol>)viewModelForModelObject:(id <HikeChatCellModelProtocol>)modelObject {
        HKMessageViewModel *viewModel = nil;
        
        if ([modelObject isKindOfClass:[HikeUserMessage class]]) {
            viewModel = [self viewModelForUserMessage:modelObject];
        } else if ([modelObject isKindOfClass:[HikeSystemMessage class]]) {
            viewModel = [self viewModelForSystemMessage:modelObject];
        }
        
        return viewModel;
    }
    View Model Initialisation
    • Action Handler — The view reports all user actions taken on it back to the Controller. In order to keep the Controller independent of the business logic behind all such user actions, we place all this logic in a separate component called Action Handler. This component gets the information regarding the type of action (say single touch, long press etc.) from the Controller, and applies all business logic to handle that event:
    + (void)handleActionOfType:(HikeActionType)type
                      forModel:(id <HikeChatCellModelProtocol>)modelObject
                initParameters:(nullable id<HikeCellActionInitParameters>)initData
              navigationAction:(nonnull void (^)(HikeChatCellActionResponseModel * _Nonnull))responseModel {
    
    //Appropriate business logic to handle the user action on cell
    //Return a response model object based on all business logic.
    }
    Action Handler

    It is important here to note that while the Action Handler has all the logic to execute in response to any user action, it doesn’t actually perform any UI operations itself. Any UI operation, be it adding/removing a subview, or pushing/presenting any other View Controller should only be done by the Controller. As we can see in the above snippet, the Action Handler returns a Response Model object. This object contains all information about the kind of UI task that needs to be performed:

    @interface HikeChatCellActionResponseModel : NSObject
    
    @property (nonatomic,assign) HikeChatDisplayType displayType;
    @property (nonatomic,assign) HikeChatActionType actionType;
    @property (nonatomic,strong) UIView *view;
    @property (nonatomic,strong) UIViewController *viewController;
    
    @end
    Response Model

    Based on the value of the action type, the Controller picks the appropriate UIView or UIViewController from the Response Model object and performs necessary operations on it. Thus, there is a clear separation of responsibility between the Controller and the Action Handler.

    Conclusion:

    This hybrid design pattern offers us multiple advantages over other patterns. When we applied it in app

    • Our Controller classes have become very light weight, with its only responsibility being that of connecting all other components together. This has improved the testability of this component
    • The Data Source kept the implementation of how data is stored abstracted, and this could be changed at any later point of time without affecting other components
    • The Views/ View Model become reusable as they were only identified by adhering to a protocol
    • Unit Testing becomes easier and could be done only for classes with a business logic in them.
    • Most if-else checks in the code were minimised by using factory pattern to link different components.
    • The readability of the code increased, helping other developers understand what’s going on in your features 🙂

    Impact at Hike:

    • The architecture helped us improve the overall app stability. We started implementing it at one place at a time. We began with chat, and this helped us make chat more robust and easy to work upon. For instance, here’s how our app stability grew over time:

    • We were able to experiment internally with different versions of chat, as it was easy to just plug and play different components. This helped us make decisions faster.
    • The decision of choosing a design pattern will go a long way with you. Make sure you give enough thought to it
    • There are enough patterns out there, but you don’t have to necessarily choose from them. Feel free to come up with your own version based on your requirements

    Key takeaways:

    • The decision of choosing a design pattern will go a long way with you. Make sure you give enough thought to it
    • There are enough patterns out there, but you don’t have to necessarily choose from them. Feel free to come up with your own version based on your requirements

    每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,欢迎关注开源日报。交流QQ群:202790710;微博:https://weibo.com/openingsource;电报群 https://t.me/OpeningSourceOrg

  • 2018年10月2日:开源日报第208期

    2 10 月, 2018

    每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,欢迎关注开源日报。交流QQ群:202790710;微博:https://weibo.com/openingsource;电报群 https://t.me/OpeningSourceOrg


    今日推荐开源项目:《Docker docker_practice》传送门:GitHub链接

    推荐理由:Docker —— 从入门到……别担心,这个并不会让你入土。这个项目是一本 Docker 教学书,同时适合初心者和老手,如果想要学习 Docker 的话,这本书应该能成为不错的资料。


    今日推荐英文原文:《Developers, Truths and Myths.》作者:Marcus Low

    原文链接:https://blog.usejournal.com/developers-truths-and-myths-9e7296c0c253

    推荐理由:对于开发者的错误理解,虽然第四条大多数时候可能都是对的……

    Developers, Truths and Myths.

    I closed the project files for the last time on the WingIDE. I wrote my last code a year ago, when I was 44. Managing developers has taken up most of my time and giving up coding was a natural decision.

    Contrary to popular belief, developers are not difficult to figure out and I’ve spent a huge chunk of my career on sorting, hiring, training, and motivating the good seeds. Developers also have loads of assumptions about the business world and the people within it, which I will try to address here in a bit. But first, some background about myself from when I first started off as a young developer with a devil-may-care attitude and courageous wit to beat.

    I started developing when I was 14, wrote and sold my first commercial game in high school at 15 and nabbed my first job in Antivirus development after graduation. Throughout the tenure of my employment, I wrote one of the earlier macro virus real-time detection systems for Armour Antivirus, and a personal firewall for Norman Data Defense System, which then led to the start of my own company, InternetNow, at 27. Back then, there were hardly any companies offering internet solutions, less with the word “Internet” attached to their brand.

    In 2006, I was invited to be a key speaker for a Jobstreet event and I spoke on the topic, “Can I be a developer for life?”. The response was overwhelming with developers of all ages and skill packing the event space till there was hardly any leg room left.

    Those days, the developer community in Malaysia was untapped and one of my important milestones was founding a local Python User Group with a fellow developer and coding enthusiast, Jeremy Johnson. At that point, I was predominantly developing on Windows so starting this community actually widened my exposure and reach to other ecosystems. I haven’t looked back since. I left my company in the hands of capable partners and joined a startup in 2015.

    Now that you know more about me and can perhaps better relate to my torrential prose (I am after all not a writer, but a developer at heart), let’s take a look at some truths and myths about working with developers and the characteristics they tend to embody.

    1. They can’t talk to humans, they can only communicate through computers

    Mostly FALSE

    This myth surfaced roughly during the 90s with the explosion of programming jobs for desktop Windows taking on nearly the entire market. Suddenly, companies were hiring teams consisting of self-taught programmers and IT graduates to help out on new hardware deployment, maintenance or applications development tasks. And to the more traditional hires, these new talents tend to be viewed as overtly quirky and a tad different in personality compared to everyone else. There is a reason for that.

    Programming is a skill. Like any other skill, you have to spend time honing them. Google didn’t exist back then and neither did tools like StackOverflow or Github. Programmers had to learn everything by coding and experimenting on their own — there were no cut+paste type of “developers”. The amount of time required to commit to these learnings meant sacrificing lots of socialising time and midnight teh-tarik (Malaysian version of coffee) sessions.

    This lifestyle leads to a lack of EQ and difficulties in initiating conversations amongst non-developer crowds. Some may eventually warm up to it but others tend to remain socially awkward for a long time. Behind the keyboard, however, is a livelier story.

    2. They hate salespeople

    FALSE

    Hate is a strong word, but let’s not digress. On a serious note, the fastest way to shut down a programming team is to put a salesperson in charge of running it. Specifically, a salesperson with a lack of domain knowledge can kill any team faster than you can type “Hello World”

    Overall, it has more to do with respect and respect has to be earned.

    Scenario #1

    A sales or marketing person (often it can be the owner / founder) walks to a team and says “I need this in 3 months” and will be honestly shocked when the dev team reports that such a project would require at least 6 months. Sometimes this gap becomes unbearable and a project manager is hired to conduct a detailed progress report and he/she would have to try very hard to explain why a project takes excruciatingly long to complete. This is often the job of the CTO, project manager or even product owner.

    Scenario #2

    A developer decides to create her own company and partnered with a friend in business development. When sales start picking up, the business development partner realises that it’s a lot of hard work selling their services; using her own car (chalking up high maintenance and petrol costs) and getting pinged at all hours by clients on technical issues. The partner then starts to demand more reimbursements from the company, foregoing the pre-set “equal salary, 50–50 split” expectations. The developer now feels she is being short-changed and these terms are no longer honorable.

    Somewhere down the line, the partner figured out that she could find other products/services to re-sell and the partnership with the dev was no longer “fair” or necessary. It’s a situation of how salespeople tend to overrule tech. Happens more often than not.

    Fact is, devs don’t hate salespeople but they don’t like to be jerked around with empty promises and by leaders with no technical knowledge whatsoever. Some companies value sales innovation over services innovation, a classic example would be how sales actually improved after Steve Jobs was evicted from Apple, but those figures didn’t end well without innovations. Startups on the other hand, need a lot more sales validation than idea generation.

    3. Developers are difficult to retain

    TRUE

    Software developers, programmers, code writers, blockchain developers, full stack, backend, front end, the list goes on.

    These are all various descriptions of the same role. A subpar developer will deliver mediocre codes at best but a good one will be able to pick up on new languages, platforms and generally code better even at a late start.

    Tech jobs have been all the hype since tech companies entered the limelight and their shares have been skyrocketing faster than traditional companies. Hence, turnover is at an all time high.

    If you want to keep quality developers, you only need to understand a few things.

    a. Kill their boredom. Repetitive work and unchallenging tasks are what drives good developers away.

    b. Hire a manager/VPE/CTO that understands coding and have some interest in the things that developers are passionate in. Developers often share common interests in games and movies so buzzwords like Counter strike, Dota2, League of Legends, The Matrix, Dark soul (hehe), are what team leads need to know in order to sync well with the team dynamics.

    c. Flexible time and good resources breed the best developers. Force a 9–5 work schedule on them and you get a 9–5 product. Veteran developers do not buy into dream speeches or working with impossible deadlines. Good luck if you’re a startup with a shaky business model.

    Flexibility is about trust. There are just three(3) types of developers in this scenario:

    1. Those who enjoy this flexibility and would be productive in contributing.
    2. Those who will abuse it by procrastinating and producing mediocre work.
    3. Those who will use the extra time to moonlight.

    Fire #2, coach and challenge #3 and reward #1.

    4. Developers are destined to be single

    FALSE

    Some developers believe this is their fate. Remember how I mentioned that developers might have some issues making friends? It’s the same way, romantically. But in the 20th century, things have changed. If anything, being a developer is considered sexy — pays well and comes with a “certified intelligent” stamp — Intel Inside.

    My advice is just be confident and most importantly, be yourself. I can testify to this, as I have a ring on my finger. Also, Sheldon Cooper, Leonard Hofstadter and Howard Wolowitz from “Big Bang Theory”, all married, nuff said

    5. Coding is not an age-friendly job

    TRUE

    At some point in time, it wouldn’t be. This is because you should have acquired enough experience and skill to guide the next generation in coding and architecture. This has nothing to do with intelligence, but given the nature of technology, new tools and services may require you to adopt knowledge quickly. Lesser energy and higher commitment that comes with age does not work to your advantage.

    Look at typical 40-year-old developer, John and 28-year-old Amy.

    John has to attend his kids’ rehearsals, occasionally ferrying his ageing parents to and from the hospital and helping out with chores at home. Weekends are packed with grocery shopping, house fixings and family time.

    Amy, on the other hand, is thinking of which workshop to participate in, which event to socialise at, taking on interesting projects to boost her skills.

    Which of these two will fare better in learning a new language or adopting a new technology, assuming they are both coding for the same task?

    Here is the good news.

    You can’t beat a team of developers led by a veteran lead who is willing to share, coach and guide the team.

    Younger developers often see themselves as the “striker” in a football game. The problem is that everyone wants to be a star striker so when the game starts, you have a bunch of high energy, high potential players running towards the goal posts without a proper strategy. The game ends up with massive losses, lots of red and yellow cards flashed, and maybe some players in the hospital.

    So if you are a developer with decades of experience, be a team lead, guide and coach instead of a coder, as that will contribute to the company significantly. Think VPE and CTO positions and spend your time learning up managerial skills, objectives and key results (OKRs), tracking measurements and pitching your technical experience to obtain projects, AWS/GCP credits and attract talents.

    If you are the sole developer in your own company, it’s time to let go of those legos, share your wealth and trade for time.

    Experience is gold, it allows you to avoid pitfalls or make a wise decision. I will close this point with a story for you to ponder upon.

    Ages ago, when the priests and kings wanted to preserve the writings and commandments given to Moses, each new king was asked to make a copy for himself, then read and understand every word written. Anyone who copies the words considered them sacred and are careful not to add or remove any words that were passed down. With each generation, anyone with the possession of a new copy could compare and validate it to past versions. This prevents inaccurate duplications and deliberate “additions” to the original. So the “oldest” copy have no merit if the majority disagrees with it, this prevents age to be the variable of being “original”.

    Today, this ancient methodology is called BlockChain.

    5 kinds of developers that you may want to avoid hiring.

    1. The Shallows

    These are sales guys passing off as developers. You can tell by the amount of GitHub projects they copied from other GitHubs or in recent trend, Kaggle clones. Their work shows a shallow technical capability that would impress non-techies and sometimes your bosses. In a team, he/she will usually be the one who enjoys steering communication towards non-essential discussions and often turns up at every event in the community to be in a crowd.

    In a nutshell, these are people who insist on sticking to development without spending much time or effort on honing his/her craft.

    2. The Entrepreneurs

    These are developers who spend way too much time attending and winning hackathons, flaunting their status as an entrepreneur, CEO or some other hippy titles, yet with the skills and expertise that remains questionable. They may construct beautiful presentations and pitch decks, but falter when it comes to the actual execution.

    After all, if you believe in your ideas that much, why will you waste time attending hackathons with a different idea each time.

    3. The Rambos

    Rambos are good developers with a decent set of skills and experience under their belt. They give off a vibe of competency and are often active in the tech community, open source projects and 101 other things. Sounds like a quality hire, right?

    Here’s the issue. They often overcommit to various projects and consultations, being a jack of all trades and master of none. The lack of focus could be a problem, although there are a few gems of focused Rambos who will add significant value to any team.

    4. The EMOs

    There is this person who would always tweet/FB about how the world is against him/her. Every project request is torture and every feedback, a stab to the heart. While he/she can undoubtedly code, there is this certain element of negativity for everything that happens to them. Often this person will prefer and be asked to work solo.

    I have always found such developers to be an enigma and highly undependable in any task.

    5. The Perfectionists

    “Follow this specific coding convention”. “Use this exact implementation pattern”. The perfectionists are often “by the book” when it comes to codes. While it is near impossible to argue against the “good” that will come out of it, these perfectionists will spend way too much time getting things done, hence affecting overall delivery.

    Almost like an artist, a perfectionist developer would rather starve and fail than deliver a product with a slight notch. While they are not exactly bad hires and will thrive in corporates or enterprises that need major cleanup assistance on existing codes, startups who require untested features to be validated may find these type of developers a nightmare to work with.

    Finally.

    HUXNNLALMRRCKFDYAKIH

    H3NEAELAAOITUTRREMAO

    TLDTTBMCLRODCENIEAOA

    EAMNROTIOVVRIIANNHAA

    TTTKIXACRR1HEMCANCNI

    ANNA, there u go.

    — cover photo is for illustration, photography is a popular hobby among developers 😉 ig : marcus_low


    每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,欢迎关注开源日报。交流QQ群:202790710;微博:https://weibo.com/openingsource;电报群 https://t.me/OpeningSourceOrg

  • 2018年10月1日:开源日报第207期

    1 10 月, 2018

    每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,欢迎关注开源日报。交流QQ群:202790710;微博:https://weibo.com/openingsource;电报群 https://t.me/OpeningSourceOrg


    今日推荐开源项目:《字典 chinese-xinhua》传送门:GitHub链接

    推荐理由:中华新华字典数据库和 API,这个项目里面包含了成语,词语,汉字甚至歇后语都有,如果有想要做一个成语接龙或者是别的什么字典 app 的朋友,这个数据库和 API 可能会对你们有不小的帮助。当然了,兴许你也可以把这个 API 示例作为方便快捷查找成语歇后语的工具来用……


    今日推荐英文原文:《A comparison between Angular and React and their core languages》作者:Dler Ari

    原文链接:https://medium.freecodecamp.org/a-comparison-between-angular-and-react-and-their-core-languages-9de52f485a76

    推荐理由:顾名思义,对比 Angular 和 React 以及它们的源码

    A comparison between Angular and React and their core languages

    In this article, we will compare two of the most popular web technologies in 2018, and also address their history, key differences, core languages used (TypeScript and JavaScript) and so forth. Overall, these technologies have made it much easier for developers to reuse, refactor, and maintain code by dividing things into modules/components.

    The goal of this article is not to find the best technology, but to compare, highlight, and clarify few misconceptions. We’ll also focus on what is important instead of minor details that do not really matter in the long-term.

    You should be aware that the comparison between these two technologies cannot be fully covered. Angular comes with a complete framework (MVC), while React is a fronted-library with lots of open-source packages to integrate with.

    Note! The word technologies is a replacement for Angular and React.


    If you want to become a better web developer, start your own business, teach others, or simply improve your development skills, I’ll be posting high-quality weekly tips and tricks on the latest web-languages out in the market.

    Questions to be addressed

    • What are the key differences between Angular and React?
    • What makes TypeScript so special?
    • How popular are these technologies?
    • What is the current open-source status?
    • Which technology do companies use the most?
    • Do static typed languages influence code quality and development time?

    Future sections will be added based on demand from the comments.

    Key comparisons

    Here’s a quick side-to-side comparison between Angular (left) and React (right).

    Angular and React

    One thing that is really great about React in terms of performance is the Virtual DOM, which you’ve probably heard about a couple of times. If not, don’t worry, I’ll explain it!

    Problem
    Let’s say you want to update a user’s birth date within a block of HTML tags.

    Virtual DOM
    It only updates the part that is required by seeing the differences between the previous and current HTML version. Its a similar approach to how GitHub operates when detecting changes in the file.

    Regular DOM
    It will update the whole tree structure of HTML tags until it reaches the birth date.

    Why does it matter?

    It may not matter for the problem described above. However, if we deal with 20–30 asynchronous data requests on the same page (and for every page request we replace the whole HTML block), it will influence performance as well as user-experience.

    Need more context? Check out Dace’s article!

    But first, back to the beginning…

    History

    We’ll need to know a bit of history (context) because it provides insight into how things may shape up in the future.

    I will not go into the details of what exactly happened between Angular and AngularJS, and I’m sure there are lots of resources available that cover it. But in short, Google replaced AngularJS with Angular, and JavaScript with TypeScript.

    Alright, so back in the days with ES4/ES5, the learning-curve for JavaScript was really high. If you came from the world of Java, C# or C++, a world of object-oriented-programming (OOP), then learning JavaScript was simply not that intuitive. In other words, it was a pain in the ass.

    It’s not because the language was poorly written, but because it has a different purpose. It was built to handle the asynchronous nature of the web, such as user interaction, event-binding, transitions/animations, and so forth. It’s a different animal with different instincts.

    Popularity

    As Google Trends reveal, Angular and React are two of the most popular web technologies in 2018.

    Angular has more search hits than React, however it does not necessarily mean that one is better than the other. But this indicates what people find interesting, whatever the reason may be. It’s important to be aware that people may exchange between keywords such as AngularJS or Angular, and thus lead to higher search hits.

    One thing is for sure: both technologies are growing, and the future looks bright. But still, we have to remember what happened to AngularJS. It may even happen to React, but I guess that’s the nature of the business, which we all are a part of.

    Google Trends Angular vs React

    Open-source

    React has over 100,000 stars, along with 1200 contributors and close to 300 issues waiting to be resolved.

    React has an a time-to-market advantage, since it was released 3 years prior to Angular. And that means it has faced lots real-world problems, gone through critical tests, and overall has developed into an adaptable and flexible fronted-library which many love.

    When it comes to Angular, at first glance, we can clearly see that Angular has 6 times more issues than React (not good). However, we must not forget that Angular is a much larger framework, and also has fewer developers using it (currently) because it was released in 2016.

    Angular and React — Github popularity

    What companies are using

    React was initially developed at Facebook for Facebook to optimize and ease the development of components. An article written by Chris Cordle points out that React has a higher usage at Facebook than Angular has at Google.

    So who uses which technology?

    # React

    • Facebook
    • AirBnb
    • Uber
    • Netflix
    • Instagram
    • Whatsapp
    • Dropbox

    # Angular

    • Eat24
    • CVS shop
    • onefootball
    • Google Express
    • NBA
    • Delta

    If you know of any large, well-known companies using Angular, please share with a link.

    TypeScript and JavaScript (ES6+)

    As I mentioned, it can be misleading to only compare Angular and React without focusing on the core language each one has to offer.

    TypeScript (left) vs JavaScript (right)

    In terms of user base, JavaScript has by far the larger one. But TypeScript is gradually increasing, so who knows what 10–15 years will bring. Maybe a couple of dozen new frameworks (sarcasm).

    Google trends — TypeScript and JavaScript

    TypeScript was initially developed by Microsoft to make JavaScript easier (in other words, to make ES5 easier). It was released in October 2012. And it is simply a transpiler that compiles TypeScript to JavaScript code, which also means you can write ES5 code in a TypeScript file.

    In general, TypeScript provides a smooth transition for programmers with an Object Oriented Programming (OOP) background. It is important to notice that TypeScript was released in the period of ES5, and during that time, ES5 was not a class-based OOP language.

    In short, the closest you could come to classes and objects back then was through prototype inheritance. And as we know, this was a difficult transition for most developers with an OOP background. So the ideal decision was of course choosing something you felt comfortable and familiar with, which was likely TypeScript.

    However, in the past years, JavaScript has evolved and implemented lots of great changes such as modules, classes, spread operators, arrow functions, template literals and so on. Overall, it allows developers to write declarative code, while supporting the characteristics of a true OOP language (that is, including class-based structure).

    Statically and Dynamically-typed languages

    A statically typed language basically means that you can define the variable type (string, number, or array etc). You may ask why this is important. Here’s a real world analogy I’ve setup (creativity at its best).

    Let’s say you want to refuel your car with gas. One thing that is important is to fuel with the right gas — petrol or diesel. And if you don’t know, you may need to buy a new car.

    Of course, the severity is not like that with coding, however, in some cases it may be. Think about it. If you work with a large application, you would like to know the argument and property type that is passed, otherwise you may break the code.

    Alright, so if you are still confused what statically typed means, check this out:

    Static typed property

    Static typed property comparison between JavaScript and TypeScript

    Static typed argument

    Static typed argument comparison between JavaScript and TypeScript

    I’ve learned that lots of people believe that a statically typed language means reliable code, and is most often used as a winning argument over dynamically typed languages. And frankly, it is quite difficult to disprove this statement because it fundamentally relies on the development environment, the programmers experience and of course the project requirements.

    Luckily, research (tl;dr video) has taken this seriously, and put this myth to test with 49 subjects.

    The observations from the research are:

    • Statically typed language require more time due to fixing typo errors
    • Dynamically typed language is readable and easier to write (declarative code)

    Figure 5 shows that, on average, developers reduce their development time by a factor of two when writing a dynamically typed language.

    If you want to dig deeper into this topic, I suggest reading this article by Eric Elliott which states that you may not need TypeScript (or statically typed languages).

    What to choose

    So the question is not only about what Angular or React offers, but also about what core language you should invest time on. And it does not really matter to be honest.

    But if we had to select, then it seems that the reasons TypeScript stands by in contrast to JavaScript are not that many. And I don’t really see why people would neglect JavaScript (ES6+). Anyway, if you are not a fan of types, then there is nothing standing in your way of writing ES6 code in .ts file. It’s just that if you need it, then it is there.

    Here is a simple class-object comparison between TS and JS (ES6).

    TypeScript
    JavaScript (ES6)

    IMO

    Statically typed feels structured, secure, readable, and easy to collaborate with others (prevents people from passing unexpected values). However, when working with dynamically typed, I have the flexibility and creativity to focus more on creating than thinking to much about types, interfaces and generics and so forth.

    And from the past web-apps I’ve built, I haven’t really had any large issues with not having static typed. It does not mean I don’t like it — I just that I don’t need it, but maybe I do in the future.

    Takeaway notes

    • React handles memory-management efficiently (virtual DOM)
    • React uses JavaScript (ES6), a recognized web-language since 1995
    • Angular uses TypeScript, released in 2012
    • Statically typed languages are great, but you can do fine with without it
    • Dynamically typed languages require less time to write and more flexibility to use your creativity (fewer typos)
    • Learning a statically-typed language may be a challenge, especially if you’ve only been working with dynamically typed languages
    • ES6 has implemented lots of great features such as modules, classes, spread operator, arrow functions, template literals that allows you to write less, cleaner and more structured code (syntactic sugar)
    • TS is simply ES6+ with typos and more

    Conclusion

    The framework/component-library you choose may influence how much time you spend programming and your budget. If you have a team with C#, Java or C++ developers, then I would probably go for Angular, since TypeScript shares many similarities with these languages.

    The best recommendation I can offer is to setup a basic application both in Angular and React, and then evaluate the language and work flow before you make a decision.

    As previously mentioned, both technologies have their own set of advantages and similarities, and it really boils down to what type of requirements the application offers.

    Want to learn more about the web-ecosystem?

    • Core Web Concepts
    • Important JavaScript methods
    • Create Custom Bash Commands (for Linux/MacOS developers)

    You can find me on Medium where I publish on a weekly basis. Or you can follow me on Twitter, where I post relevant web development tips and tricks along with personal stories.

    P.S. If you enjoyed this article and want more, please clap ❤ and share with friends that may need it, it’s good karma.


    每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,欢迎关注开源日报。交流QQ群:202790710;微博:https://weibo.com/openingsource;电报群 https://t.me/OpeningSourceOrg

  • 2018年9月30日:开源日报第206期

    30 9 月, 2018

    每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,欢迎关注开源日报。交流QQ群:202790710;微博:https://weibo.com/openingsource;电报群 https://t.me/OpeningSourceOrg


    今日推荐开源项目:《这可不是 CSS CS-Notes》传送门:GitHub链接

    推荐理由:CS 是 Computer Science 的缩写,那么顾名思义,这个项目就是关于计算机科学的学习笔记,包括了算法,操作系统和数据库这些,这么一看 CS 还是包括了相当大的方面,有兴趣学习这些的朋友可以来看一看。


    今日推荐英文原文:《The Limits of Computers That Read Our Minds》作者:Yiting Sun

    原文链接:https://medium.com/neodotlife/changle-zhou-brain-machine-interface-6ec27c9a853e

    推荐理由:实际上,即使是把人类大脑和计算机以某种方式连接起来,计算机也很难比得上人类大脑

    The Limits of Computers That Read Our Minds

    A professor in China builds a brain-machine interface that keeps humans fully in charge.

    How do you teach robots to dance? Changle Zhou thinks he can do it by getting the machines to read our minds.

    In an experiment that began last year, Zhou, a computer scientist at Xiamen University in China, invited six people to sit at a screen and watch videos of a humanoid robot moving its arms. All of the humans wore an electrode cap that recorded signals from their brains. That let the researchers analyze changes in the activity of “mirror neurons,” which fire when you’re performing certain actions and when you’re observing others perform the same actions.

    For the next few years, Zhou and his graduate students will gather more and more of this data from human brains. Eventually, he says, just by thinking about what they want a robot to do, people will be able to instruct machines to make the movements necessary to boogie.

    But Zhou’s real objective isn’t just to get robots to fit in on the dance floor. The long-term goal of this research is to figure out the optimal way for humans and machines to communicate at the speed of thought.

    Zhou is one of many people trying to develop brain-machine interfaces. But while some projects aim to upgrade the way we interact with computers — letting people type and move a cursor on a computer screen through mind control, for example—Zhou is also trying to also upgrade the computer in the process. It’s a way to get machines to think more like we do and become much more useful.

    However, he’s careful to note that his vision for human-computer connections stops short of the one held by people known as transhumanists, who think an upward trajectory of machine intelligence should bring about computers that are adept and perceptive enough to serve as the substrate of human minds. Transhumanists hope to fully merge with these machines, whether it’s to enhance their own biological brains or, better yet, to become immortal. “Why should we be restricted minds?” says Ben Goertzel, a Hong Kong-based AI researcher and chair of Humanity+, an organization that envisions liberating humanity from the constraints of biology using technology.

    Zhou doesn’t buy it. Unless advanced quantum computers somehow change everything, he expects machines will remain inferior to human brains — even if they can plug in more directly to us.

    Teamwork

    Zhou has spent the past 30 years trying to build artificial intelligence that resembles human intelligence as closely as possible. He wanted machines that could understand metaphors, compose music and poems, and perhaps even express emotions. But even though he and others have designed algorithms that can make computers write, draw, and carry out other individual aspects of human creativity, he couldn’t get past the realization that machines can’t have what he considers the highest form of intelligence, something akin to Zen enlightenment. The algorithms that write songs and poems are not able to actually experience the beauty of these works.

    Zhou believes that what distinguishes the human mind from other intelligent systems is consciousness of internal experiences, or mental self-reflection. He points to our own subjective experiences of sensory inputs, which are known as qualia. “Humans can feel a sense of happiness because of qualia, not because of high IQ,” says Zhou. “Machines do not have this ability.”

    That’s why he started thinking about a hybrid system: a brain-machine interface that could draw on “the intelligence of both people and machines,” says Zhou. “This is the future path.”

    In this approach, qualia would be still be left to the humans. In his dancing robot project, a biological brain experiences the charm of the dance, and the robot “brain” is responsible only for carrying out the task. He envisions a slew of applications in which people get enjoyment from seamlessly making a machine do things that they don’t have the physical capacity to perform. But it’s not a two-way street. The robot that reads minds is merely a surrogate for a person’s imaginary actions, and only the human brain gets to have internal experiences.

    During a transhumanism conference held by Humanity+ in Beijing recently, Goertzel described ideas that might sound roughly similar. He envisions a machine whose intelligence would be as agile and nimble as a human’s. It’s beginning with a decentralized network of AI algorithms called SingularityNET, and independent developers from around the world can contribute to the network. Eventually, Goertzel imagines, it will evolve into a “self-growing and self-pruning” human-level AI. If we merge our minds with it, we would create a “superhuman AI mind,” says Goertzel.

    In that vision, superhuman AI will be the culmination of some ingenious computer engineering, and then humans will want to link their physical bodies with it. But to Zhou, a human-machine collaboration comes first and stays primary. He sees it as the means of creating the best possible AI.

    You complete me

    There are a few different tools for measuring brain activity, and the invasive ones aren’t likely to attract many volunteer research subjects. So Zhou’s team uses the electroencephalogram, or EEG. The people controlling the robots attach electrodes to their scalps by wearing a cap, and these electrodes measure the strength of the electric fields coming from the brain. To make these signals sharp enough for a computer to pick up and analyze, a white gooey conductive gel is injected in the space between scalp and electrode.

    The EEG doesn’t actually provide neuron-level resolution. Instead Zhou’s group uses it to detect very brief oscillations in brain waves as someone imagines and observes certain actions. These signals are good enough for telling a robot whether to move its left or right arm and how high. But they’re not clear enough for the more complex movements that make up the rich repository of dance styles. So these more complex movements still need to be programmed in advance. Nonetheless, training a robot this way can convey aesthetics that are very difficult to write into code, says Zhou.

    There are many challenges along the way. Tianjian Luo, one of Zhou’s PhD students, is training an algorithm that can generate high-quality signals out of the noise in EEG readings. That could make it possible for a person controlling the robot to use lightweight equipment rather than being tethered to bulky wires and computers.

    Sitting in his cubicle in the lab at Xiamen University, Luo rattles off a number of ways these interfaces could improve people’s lives. Rehabilitation for stroke patients. Controlling prosthetic limbs for amputees. Safer long-distance control of equipment stationed in dangerous areas.

    Transhumanists see something even bigger from work like this, though: a new type of consciousness. Not only will people be linked to computers, they’ll be linked to the minds of other people. “We would share experience,” says Natasha Vita-More, the executive director of Humanity+. “It would be very empathetic. Once we are connected more electronically, we will get each other.”

    Freedom

    If the transhumanist ideal or even something simpler comes to pass, it’s not clear that how much it would expand human possibility in China or any other country that extensively uses computers to conduct mass surveillance and maintain social control. A Chinese project dubbed “Dazzling Snow” aims to build an omnipresent video surveillance network by 2020, covering all corners of China’s public spaces, because security is always more important than individual liberty in the country. To combat toilet paper theft in public restrooms, the Beijing city council has deployed dispensers equipped with face-recognition technology that supplies a limited amount to each person. Given that the Internet has been tamed by the Chinese government into a tool for meeting its social and economic goals, could human-machine mind melds strengthen that power?

    Zhou says it’s counterproductive to brood over the potentially dystopian uses of brain-machine interfaces. For one thing, he says, no one is close to extracting a person’s complex, private thoughts by analyzing brain signals. But more broadly, he shrugs off such fears by using a knife as an analogy. Nobody says we shouldn’t make knives because they could be used to kill people. “You’ve got to educate people to use these technologies in the right way,” he says in his office overlooking his idyllic campus, dotted by phoenix palms. “And soothe the human heart.”


    每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,欢迎关注开源日报。交流QQ群:202790710;微博:https://weibo.com/openingsource;电报群 https://t.me/OpeningSourceOrg

←上一页
1 … 207 208 209 210 211 … 262
下一页→

Proudly powered by WordPress