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

开源日报

  • 开源日报第520期:《标准结局 jojogif》

    17 8 月, 2019
    开源日报 每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,坚持阅读《开源日报》,保持每日学习的好习惯。
    今日推荐开源项目:《标准结局 jojogif》
    今日推荐英文原文:《Functional vs Object-Oriented Programming》

    今日推荐开源项目:《标准结局 jojogif》传送门:GitHub链接
    推荐理由:将视频转换成一段 GIF 自然属于不算少见的功能,但是有的时候一些 GIF 可能需要一些特别的定制——比如令人熟悉的发黄的界面以及左下角的黄色箭头加上 TBC。这个项目可以为你用视频转换来的 GIF 自动加上标准结局,顺带一提标准结局的出处是动漫 JOJO 的奇妙冒险,一部每一个看过的人几乎都会向其他人推荐的传说之作。
    今日推荐英文原文:《Functional vs Object-Oriented Programming》作者:Tomas Engquist
    原文链接:https://medium.com/better-programming/functional-vs-object-oriented-programming-e5939c8105ff
    推荐理由:面向对象和函数式编程二者的对比

    Functional vs Object-Oriented Programming

    Arguments over preferred languages (C++ vs Java, JavaScript vs Ruby, etc.) have always been prevalent in the programming community, however, programmers disagree on more than just language. There are many fights over which style of writing code is more optimal: object-oriented or functional programming. While OOP is by far the most popular programming design, many people have not even heard of functional programming. We’re going to explain the fundamental differences between object-oriented and functional programming and describe the advantages and disadvantages of each style.

    What Is Object-Oriented Programming?

    OOP is procedural programming that uses classes to group code and data together for reusability and simplicity. By separating a program into classes, it is easier to modify parts of the program in isolation. Each class is a template for a type of object or an instance of the class. When placing methods into different classes, instances of each class can easily be modified, replaced, and reused. However, mutating class instances can get complicated with larger sets of data because it’s harder to track where each instance was changed.

    By implementing methods inside a class, it is easy to mutate instances of the class. (JavaScript)

    The advantages of OOP

    Since its rise in popularity in the 1980s, object-oriented has been the principal design concept of software engineering. Java, C++, Python, and Ruby are the most commonly used OOP languages, but there are over 100 other programming languages that support OOP. These languages have been used to develop some of the most widely used programs in history. Gmail and Minecraft are written in Java, Instagram and Spotify are written in Python, Windows and OSX are written in C & C++. We will discuss four important concepts that make OOP a popular design strategy: intuitive problem solving, encapsulation, inheritance, and polymorphism.

    Intuitive problem solving

    Programmers love OOP because it is easy to learn and conceptualize. OOP places classes in a hierarchy of parents and their children. Humans organize things in a similar hierarchical manner. For example, a vehicle is something that moves things. A car is a vehicle travels over roads. A hybrid is a car that uses electricity in addition to gas. A Prius is a hybrid with five seats made by Toyota. Note that in each sentence, we use the previously defined object to help conceptualize the new, more specific object. In short, OOP makes sense to us.

    Inheritance

    Probably the biggest advantage of using OOP is inheritance, or reusing code. Going back to the Prius example, let’s imagine you are a car manufacturer. If you want to switch from producing Priuses to the Honda Insight, you don’t have to research how to make a vehicle, car, or hybrid. Why? Instead of starting from scratch, you can take your blueprint for making and work from there. In OOP, the class is the equivalent of the blueprint. Instead of starting every program from scratch, you can inherit a class that contains any methods or properties that you need (or a hybrid) and then add new features on top of it (Prius, Insight). Inheriting classes keeps your code DRY (don’t repeat yourself) and saves you lots of time.

    The Hybrid class inherits all the Car class methods while keeping access to its own class methods. (JavaScript)

    Encapsulation

    OOP allows us to create objects of a certain class. Many OOP programming languages have a way to protect variables from outside access, forcing programmers to only interact with the class through specific methods. This allows us to hide our implementation behind an interface (protecting objects from programmer mistakes) and interact with other parts of the program through these well-behaved interfaces. In addition to providing this security, encapsulation also helps us make flexible code that is easy to change and maintain.

    Encapsulation prevents the object attributes from being directly modified. (Ruby)

    Polymorphism

    The literal definition of polymorphism is the condition of occurring in several different forms. In OOP, polymorphism refers to the ability of a variable, function or object to take on multiple forms and have multiple behaviors. This allows us to reuse code in a similar way to inheritance. Going back to our previous example, let’s say we have a vehicle class with a method move. All the subclasses of vehicle can reuse this method move but with different behavior. The car subclass will start spinning its wheels, the boat subclass will start spinning its propellers, and the plane subclass will start spinning its turbines. This cuts down the work of the developers because they can now create a general class with certain behaviors and make small altercations to subclasses when they need something more specific.

    Polymorphism allows us to reuse move() with different functionality (C++)

    In dynamic languages we use for the web, this behavior is kind of built-in. Functions that accept “vehicle-like” objects already behave polymorphically, spinning the car’s wheels, and the boat’s propellers. In other languages, polymorphism is just as important but needs to be implemented explicitly.

    Without OOP, implementing this kind of polymorphism can get very ugly. “Simple” way of simulating it usually involves keeping track of type and writing if statements everywhere polymorphism is desired. Other common methods of implementing polymorphism without OOP get progressively more complex as the “level” of polymorphism increases.

    The disadvantages of OOP

    While OOP reigns king as the most popular program design, developers have certainly encountered issues with it. In many cases, the advantages of OOP come with side effects and additional burdens. In this section, we will go through some of these burdens and how they can affect programs.

    Monkey Banana Problem

    Inheritance is one of the most important concepts in OOP. It allows for the reuse of code by basing Objects or Classes on other Objects and implementing methods defined in the parent classes. Reuse of code through inheritance cuts down on redundant code and makes OOP programming seem like a no brainer, that should be a part of every programming language. But just like everything in life, there are tradeoffs that come with inheritance. The main problem has been famously stated by Joe Armstrong, the creator of the ERLANG language.
    “ You wanted a banana but what you got was a gorilla holding the banana and the entire jungle.”
    Classes in OOP may be deeply nested, which means they have a long chain of parents classes they rely on. When inheriting a deeply nested class, you must also inherit its parent class and that parent’s parent class and that parent’s parent’s parent class and so forth. Programs won’t compile until you inherit all of the necessary parent classes. A solution to this is to avoid writing deeply nested classes, but that takes away from the reusability that comes with inheritance.

    Encapsulation Problem

    Inheritance creates several dependencies between parent and child classes. It becomes difficult to understand what is happening in the child class without having to open the parent class. Furthermore, the child class has access to the parent class methods and might overwrite these methods. Encapsulation is done to prevent Object variables from being tempered by child classes. The parent class constructor in Javascript makes a deep copy of the Object and then passes it by reference. Making copies of each parent class bogs down on the efficiency of the program.

    What is Functional Programming?

    Functional programming is similar to “pure” mathematical functions. Instead of specifying a procedure to solve a problem, functional programs compose functions to produce the desired result without using ‘state’. Evaluation of these functions and their relationships are much more important than objects and relationships. Functional programming also makes very little use of variables. Variables depend on state, which changes based on the past path of a program. Once state is involved, the function can’t be evaluated in isolation — making it no longer pure.

    The advantages of functional programming

    Surprisingly, functional programming also has many of the same perks as OOP. Many of these advantages come without the burdens that come with OOP.

    Eliminate race conditioning

    A race condition exists when two different functionalities depend on a common resource. When the sequence of events occurs differently than expected by the programmer, a failure occurs. This may occur when fetching data from an API. For example, let’s say you have a method displayData(data) that uses data from an API and another method to retrieveData() that fetches it. If you run displayData(retrieveData()), the fetch may not finish in time and displayData will try to run before retrieveData is finished, resulting in an error. Functional programs do not share resources and create dependencies in this manner, avoiding race conditioning altogether.

    Polymorphism

    Wait, wasn’t polymorphism supposed to be an advantage for OOP? Yes, it still is, but the truth is you don’t need to use OOP to implement polymorphism. Interfaces will give you this without all of the monkeys, bananas, and jungles of OOP.

    Easy debugging

    Functions in functional programming are ‘pure’ i.e. you expect the same output given the same input. The functional approach stresses simple functions that provide one piece of functionality. Bigger tasks are modularized into multiple simpler functions. In theory, the lack of state makes it much easier to debug these programs.

    Reusability

    In the words of Joe Armstrong:
    “If you have referentially transparent code, if you have pure functions — all the data comes in its input arguments and everything goes out and leave no state behind — it’s incredibly reusable.”
    Because every function is pure, one can keep reusing them without ever having to worry about state. In OOP, the state of class may change, whether intentional or not and affect the results of the instance or class methods.

    Disadvantages of functional programming

    You can’t really break down the disadvantages of functional programming into different categories. The one main problem with functional programming is quite straightforward: it’s very hard. Because we don’t have the structure and organization that comes with OOP, writing and reading complex functional programs is quite difficult. When lovers of functional programming claim that it is easier to debug and is more reusable than OOP, you must take it with a grain of salt. While it is true that pure functions don’t rely on state, they still can get complicated, difficult to follow, and hard to debug.

    Conclusion

    Clearly, it’s not so easy to pick a side between OOP and functional programming. The good thing is, you don’t have to. The only thing you have to determine is where to use each approach. Some programs might be better off written with object-oriented design while others might be better off written with functional design. Some programs might be better off using a combination of both. As a programmer, it is your job to make these choices. Hopefully, you can now make these informed choices.
    下载开源日报APP:https://opensourcedaily.org/2579/
    加入我们:https://opensourcedaily.org/about/join/
    关注我们:https://opensourcedaily.org/about/love/
  • 开源日报第519期:《极小化 bilimini》

    16 8 月, 2019
    开源日报 每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,坚持阅读《开源日报》,保持每日学习的好习惯。
    今日推荐开源项目:《极小化 bilimini》
    今日推荐英文原文:《Want to Learn Java Quickly? Burn All Your Java Tutorial Books》

    今日推荐开源项目:《极小化 bilimini》传送门:GitHub链接
    推荐理由:将 bilibili 的界面变得很小从而可以轻松在电脑上使用的项目。兴许有的时候你想要一边写东西一边看看 B 站新番,或者是苦于笔电屏幕不够大,或者只是干脆的想摸鱼,这个项目就能解决这些问题,它能够把 B 站的界面减小到你能看清但是又不太占空间的位置,并且保持在屏幕最前便于观看(因使用此项目摸鱼导致的错过 DDL 等一系列后果请自行承担)
    今日推荐英文原文:《Want to Learn Java Quickly? Burn All Your Java Tutorial Books》作者:John Selawsky
    原文链接:https://medium.com/javarevisited/want-to-learn-java-quickly-burn-all-your-java-tutorial-books-6d06f5d77e84
    推荐理由:在学习时不能够只学习理论而忽视实践

    Want to Learn Java Quickly? Burn All Your Java Tutorial Books

    Every day, the Java programming world is flooded with beginners who crave to learn the Java language. It’s not surprising that you are as well.

    The benefits of coding in this language are nearly endless. Being one of the most popular and in-demand languages in the world, you certainly can’t learn Java and be jobless!

    But it isn’t just the massive earnings that make it a juicy skill to acquire as a programmer: it also makes learning other languages much easier. And of course, you can easily learn Java, if you know the right way.

    And that is the problem…

    Unfortunately, most of the time, beginners get frustrated along the way. While it’s possible that this could be the result of other factors, it’s largely a question of adopting the wrong approach to learning Java.

    What Is the Wrong Approach to Learning Java?

    Probably the top thing that popped up when you first typed “how to learn java” into Google is “full java tutorial”. Then, you clicked through and what hit you first was a chunk of theoretical gibberish or some bulky book that took you back to high school. You tried to read it, and before you hit the end of the first part, you were left more confused than when you started.

    That’s not to say that theory is bad altogether. It’s not. Every learning process requires theory in order to explain the details. What kills it is sticking to theory alone when learning a programming language.

    And what most so-called java tutors do — teach a practical skill in theory — is outright wrong. That never works out well.

    Why?

    First of all, it drains your passion and motivation. In the words of a popular scholar: “the textbook never teaches”. Theory doesn’t drive your passion for learning. In fact, reading theoretical tutorials on java only isolates you from learning it. While it may build up some knowledge in you, it certainly can’t make you a good Java programmer.

    Second of all, theory slows down your learning. In the time you’ve spent reading some bulky textbooks, you could’ve made massive strides in your learning through practice. Avoid the terrible mistakes some students make. I get it all the time. Just recently, a few students approached me with this issue. They confided in me as a Java expert and tutor and opened up on the frustrations they encountered while learning Java. They confessed they had studied Java for over a year and were still confused by how codes work. Really?

    Yes, it’s laughable. But hey, a lot of Java students suffer the same fate. And the reason is simple: they chose the wrong approach to learning — theory!

    So, What Approach Works Best When Learning Java?

    Practice makes all the difference. The benefits are almost endless:
    • Practice leads to professionalism. I was able to become an expert Java tutor because of constant, repeated practice. Certainly, this is the key to the success of professional programmers. You’re just going to have to code it!
    • Helps you learn. Applying the knowledge to real-life cases enhances your prowess.
    • The more you practice, the more you discover, including things you didn’t realize weren’t to your knowledge yet.
    • Guides you to code by hand. It gives a lot more to your skill than the fancy tools and frameworks. You get a better understanding of the coding logic.
    • Helps you solve practical problems. With practice, you can appreciate problems better, understand their dynamics and offer appropriate solutions.
    Indeed, the place of practice in learning the Java programming language is irreplaceable. In fact, learning Java begins and ends with practice, especially when it is an individual doing the learning.

    Online Sources Where You Can Learn Java

    As indicated earlier here, your success in learning Java depends on several factors. While constant practice is a key factor, learning on the right platform is equally important. But you have to watch it. The internet is replete with different sources claiming to know and teach Java perfectly. You should be wary when making your choice.

    Here are my top picks for platforms and sources where you can access practical Java instruction.

    CodeGym


    CodeGym.cc has IntelliJ IDEA integration plugin

    CodeGym is appropriately named. It is exactly the place where you can work out your Java coding skills. Learning on the platform is 80% practical. This gives you the opportunity to learn much faster than usual. You must code, code, and then code some more! And that is what the platform offers you.

    You will have to execute 1,200 practical tasks. The tasks are arranged in order of complexity, so you start with the simplest, and advance to the hardest. When you complete your tasks, they will check your work and grade you.

    Codecademy


    You may as well be among the hundreds of programmers the platform has trained globally over the years. They offer a practical learning experience to students mastering Java, among other languages. They are also quite good at working with beginners. So, they help you plan your learning based on which area you choose to focus on.

    And don’t forget, you can plan and schedule your time on the platform for better learning.

    Coursera


    When you visit the Coursera site, the first thing that hits you in the face is “join for free.” Well, don’t take it to be “just a freebie.” You have a powerful platform where you can learn Java quickly and even earn a certificate. That’s where the payment comes up.

    While it isn’t entirely free to learn on the platform, you can agree it’s worth it. They issue certificates from accredited partner universities. There are learning materials, like videos and visuals, that can aid fast learning.

    Java Revisited


    This platform offers a slightly different approach to learning Java. There are tons of practical tutorial books you can access and code with. They teach and guide you to code in Java. So, it’s more of a mixture of theory and practice. You read the theory and then apply it.

    Some Tips to Apply When Learning Java

    While you make your choice on which platform to learn, you should note some tips that will help you learn faster and better. These tips have been generally helpful to both beginners and experienced programmers.
    • Don’t be afraid to ask people. Let’s get something straight: you can hardly succeed by learning in isolation. It’s a terrible approach. While you need to give your personal focus to learning, you also need to make sure you reach out to others when necessary. Some problems you will encounter may be solved just by talking to someone. You never can tell, they may have encountered and solved a similar problem.
    • Follow the experience of your tutors. I’m often asked on my blog, which makes my students so successful. I just smile and say “well, I get them to walk in my own experience.” A great tutor has a wealth of experience you can tap into to build your own knowledge. Learn from this experience.
    • Join forums and communities for programming. There is a number of forums and communities for programmers. Join the active ones, because there is much you can learn there. You can learn from the experience of others, asks questions, and discuss and seek solutions to problems you encounter. Some of them include Java Forum, Java World, CodeGym Help, and programming subreddits on Reddit (such as learnjava and learnprogramming)
    Just to add: it’s important to understand that these forums and communities are flooded with different characters. Don’t expect to only see the good ones. In fact, there may be instances where you end up disappointed and more confused than before. It’s the age of trolling right now, so you must learn how to just ignore it.

    How to Build an Effective Plan for Self-Learning Java

    No doubt, learning Java requires planning and discipline in sticking to the plan. This is one of the secrets of successful professional programmers. How do you achieve this?
    • Make a schedule for your education and find ways to minimize distractions. You need to discipline yourself by strictly following the schedule.
    • Ask the right questions. Not every question is necessary and requires a solution. Ask relevant questions in order to get helpful solutions.
    • Start with the basics. If you are a beginner, start from the basics. Don’t jump onto just any level, no matter how simple it may seem.
    • Code every day. Practice makes perfect. You need to constantly practice. Make coding a daily habit. For instance, you can:
    • Code mini-programs.
    • Don’t shy away from coding more advanced programs using Java APIs once you cover the basics.
    • Try your hand at building at least one web and one desktop application.
    • Make the most of the blogs and forums dedicated to Java and programming languages in general. This will help you improve.
    • Use the 80% practice and 20% theory principle.
    • Continue learning every day, even after you succeed.

    Wrapping Up

    Stop collecting Java textbooks. They will do you no good. In fact, to show seriousness in learning Java set your Java books on fire.

    I guess this is a more drastic way to get you to understand that books can’t teach you coding on Java. The best way to learn is to CODE. Constant practice in coding makes all the difference, and how much and how well you do that determines how quickly you will learn.

    More so, don’t take communication for granted in your learning process. Visit forums and communities of programmers who share the same interest in Java. Share ideas, ask questions, contribute meaningfully. These will certainly facilitate your learning process.
    下载开源日报APP:https://opensourcedaily.org/2579/
    加入我们:https://opensourcedaily.org/about/join/
    关注我们:https://opensourcedaily.org/about/love/
  • 开源日报第518期:《一个顶俩 Anti-YiGeDingLia》

    15 8 月, 2019
    开源日报 每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,坚持阅读《开源日报》,保持每日学习的好习惯。
    今日推荐开源项目:《一个顶俩 Anti-YiGeDingLia》
    今日推荐英文原文:《What Is a Pure Function?》

    今日推荐开源项目:《一个顶俩 Anti-YiGeDingLia》传送门:GitHub链接
    推荐理由:成语接龙玩多了的都知道,这个世界上最可怕的成语——当然就是一个顶俩,而这个项目可以帮你找出一条将接龙导向一个顶俩的路径,或者是导向一个头尾可以自己接龙循环的词语。不过理论上可以通过修改一下源码来替换一个顶俩为另一个其他的词语,原理本身并没有变。

    今日推荐英文原文:《What Is a Pure Function?》作者:Devin Soni
    原文链接:https://medium.com/better-programming/what-is-a-pure-function-3b4af9352f6f
    推荐理由:介绍了纯函数和它的好处

    What Is a Pure Function?

    Pure functions in programming and their benefits

    Definition

    In programming, a pure function is a function that has the following properties:
    1. The function always returns the same value for the same inputs.
    2. Evaluation of the function has no side effects. Side effects refer to changing other attributes of the program not contained within the function, such as changing global variable values or using I/O streams.
    Effectively, a pure function’s return value is based only on its inputs and has no other dependencies or effects on the overall program.

    https://www.mathsisfun.com/sets/function.html

    Pure functions are conceptually similar to mathematical functions. For any given input, a pure function must return exactly one possible value.

    Like a mathematical function, it is, however, allowed to return that same value for other inputs. Additionally, like a mathematical function, its output is determined solely by its inputs and not any values stored in some other, global state.

    Examples

    The below function is pure. It has no side effects and always returns the same output for the same input.
    def add_1(x):
        return x + 1
    
    The below function is not pure. It does not always return the same value for the same input, as the output depends on the inputted x value as well as the internally-computed random value.
    import random
    
    def f(x):
        if random.randint(1, 2) == 1:
            return x + 1
        return x + 2
    
    The below function is also not pure. Even though it always returns the same value for the same input, it has side effects as it modifies the value of the global variable y.
    y = 1
    
    def f(x):
        global y
        y += 1
        return x + 1 
    

    Benefits

    There are several benefits to using pure functions, both in terms of performance and usability.

    1. Readability

    Pure functions are much easier to read and reason about. All relevant inputs and dependencies are provided as parameters, so no effects are observed that alter variables outside of the set of inputs.

    This means that we can quickly understand a function and its dependencies, just by reading the function’s declaration. So, if a function is declared as f(a, b, c) then we know that only a, b, and c are dependencies of f.

    2. Portability

    As all dependencies are provided as input parameters and are not accessed through a global context, these dependencies can be swapped out depending on the context in which the function is called.

    This means that the same function can act on different implementations of the same resource, for example.

    This makes the code much more portable and reusable as the same function can be used in various contexts, rather than having to write a different function just to use a different implementation of the same class.

    For example, instead of having to write two different impure functions to use two different loggers that are stored globally, a pure function would just take in the desired logger as an input.

    3. Testing

    The lack of side effects makes pure functions very easy to test, as we only need to test that the inputs produce the desired outputs. We do not need to check the validity of any global program state in our tests of specific functions.

    In addition, as all dependencies are provided as inputs, we can easily mock dependencies. In an impure setting, we would have to keep track of the state of some global dependency throughout all of the tests.

    However, in a pure setting, we would simply provide all dependencies as input. We no longer have to worry about maintaining global state throughout our tests, and we can now potentially provide different versions of dependencies to different tests.

    This allows us to test functions while explicitly having control over the provided dependencies in each test.

    4. Referential transparency

    Referential transparency refers to being able to replace a function’s call with its corresponding output value without changing the behavior of a program.

    To achieve referential transparency, a function must be pure. This has benefits in terms of readability and speed. Compilers are often able to optimize code that exhibits referential transparency.

    5. Caching

    As pure functions always return the same output for the same input, we can cache the results of pure function calls.

    Caching refers to using a technique, such as memoization, to store the results of functions so that we only need to calculate them once.

    Typically, for a function f: Input -> Output this is accomplished through a map (such as a hash-map) from Input -> Output.

    When executing a function, we first check if the map contains the input as a key. If it does, we return the map’s output value, otherwise, we calculate f(input), and then store the output in the map before returning it.
    下载开源日报APP:https://opensourcedaily.org/2579/
    加入我们:https://opensourcedaily.org/about/join/
    关注我们:https://opensourcedaily.org/about/love/
  • 开源日报第517期:《大菠萝 diabloweb》

    14 8 月, 2019
    开源日报 每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,坚持阅读《开源日报》,保持每日学习的好习惯。
    今日推荐开源项目:《大菠萝 diabloweb》
    今日推荐英文原文:《How to Cut Through Code Fog》

    今日推荐开源项目:《大菠萝 diabloweb》传送门:GitHub链接
    推荐理由:Diablo,即暗黑破坏神,相信就算是没有玩过它的玩家也多多少少听过大菠萝这个名号。这个项目允许你可以开着你的浏览器跑个 Diablo1 玩,随着网络的不断发展,浏览器能起到的作用越来越大了,在浏览器上重温名作已经不只是纸上谈兵,而是不断接近的现实。
    今日推荐英文原文:《How to Cut Through Code Fog》作者:Aphinya Dechalert
    原文链接:https://medium.com/better-programming/how-to-cut-through-the-code-fog-45bfddc3d9c7
    推荐理由:换个角度换种思考什么的兴许能解决一个看起来无解的问题

    How to Cut Through Code Fog

    It’s like brain fog but worse

    At some point while sitting at our desks, we’ve all experienced code fog. It’s like a mixed feeling of confusion, frustration, and exhaustion. Code fog happens when you’ve tried to compile your code and it’s just not working.

    You’ve chopped, changed, and Googled your way through every possible link. You probably have even made it to the 12th page of your Google search.

    Code fog is notorious for causing imaginary table-flips and no — you’ve checked — it’s certainly not caused by a missing semi-colon. It’s something deeper and you can’t quite figure out what.

    Rather than force yourself through the painfully unproductive process of debugging, here are some things you can do to help cure your code fog and gain a sense of clarity once again.

    Why Bugs Happen

    Bugs happen because there’s a gap in our knowledge. It’s also the main reason we instantly turn to Google when we get stuck. But oftentimes, the answers that Google gives tend to be snippets of something bigger. Sometimes, the gap in your knowledge is so big that looking at snippets is simply not enough.

    You need to take a step back and look at the bigger picture. What does this mean? First, you need to identify the type of issue you’re facing. Is your code overly complicated? Then it’s a programming pattern issue. Is your code not working the way it should? Then it’s a gap in your understanding of the framework or library. Is your code not compiling? It might be a dependency issue.

    When you have a programming pattern issue, the quickest cure is to slow down and look into functional and OOP patterns for your chosen language. If you’ve got a framework or library issue, then you need to look into the wider topic surrounding your issue. If it’s a dependency issue, you’ll need to trace the relationships and versions to figure out where the blip is.

    Don’t try to look for a solution, it’ll continue to give you tunnel vision. A big-picture approach can lead you down a very different road from what you’re currently experiencing.

    Sometimes, You Just Need a Break

    As developers, our brains can get stuck in a funky loop and cause tunnel vision towards our code if we’ve been working on it long enough. We start to see only what we want to see. When this happens, you need to give your brain a break from the issue and go work on something else. A 12 to 24-hour quarantine from the problematic code is usually enough for most of us to properly disconnect and come back to the issue with fresh eyes.

    According to the Science of Learning Journal, when we become frustrated or fearful, the part of our brain known as the amygdala kicks in. Based on past conditioning, it only makes us aware of the immediate threat — which in our case is the problematic code. The more we focus on it, the more we become entrenched in our own created mental boundaries and fail to see any systematic connections that may be contributing to the bug.

    So take a break — go and do something else, then come back to it with a different attitude and mindset towards your code.

    Seek a Second Opinion

    One of the perks of peer programming is that there is always a second opinion on your code. As a developer, we may think of our code as infallible, however, another pair of eyes with knowledge of different topics and past experiences have the ability to inject an alternative perspective.

    Most of the time, we work on our code alone, but when bugs arise, and before your brain becomes overly fixated on them, ask a colleague for help. Just have them to come over and review what you’ve coded. Get them to ask you questions about the code.

    They don’t have to solve it for you — but their questions can lead you down a different path towards your solution. Everyone has their own flow of thought when it comes to debugging and chances are that they’ll think differently from you.

    Final Words

    Code fog happens because you get stuck. To become unstuck, you need to do something that is different from what you’re currently doing. You can’t expect a different output if your input remains the same.

    Code fog sucks but it always eventually clears. You just need to be patient with yourself and work on constantly expanding your domain of knowledge. This is because you never quite know when something seemingly random will come in handy. It’s also one of the best ways to prevent code fog in the future.

    As Steve Jobs once said in his Stanford commence speech —
    You can’t connect the dots looking forward; you can only connect them looking backwards. So you have to trust that the dots will somehow connect in your future.
    Thank you for reading. ❤

    Aphinya
    下载开源日报APP:https://opensourcedaily.org/2579/
    加入我们:https://opensourcedaily.org/about/join/
    关注我们:https://opensourcedaily.org/about/love/
←上一页
1 … 129 130 131 132 133 … 262
下一页→

Proudly powered by WordPress