Posts

Javascript Generators -> Practical use case

Image
Hi Guys, it's been a while since I didn't write anything, but today I want to share with you something I faced today, while I was reviewing the code of one of my teammates did, I saw a "good" implementation of how to deal with a paginated endpoint. Basically he used recursion in order to iterate the pages, something like this: function handlePages(response) { const res = { data : response.data } if (response.pages.next_page) { res.next = async () => { const nextResponse = await request(response.pages.next_page) return handlePages(nextResponse) } } return res } It works! but I don't like the recursion part, because if we need to iterate it we need some extra logic: const response = await request(firstPageUrl) let page = handlePages(response) while (response.next) { // Complex logic here response = await response.next() } So far, this logic looks great, bu

Big O Notation, explained step by step

Image
What the heck is the Big O? do we really need it? is it really helpful? Well since I started working in Unosquare, I've heard a lot of Big O and its importance so I decided to see what's the big deal about it. //It's Important Well you know that there're 2 things that can tell us how efficient a program is: Performance: This depends on the machine it is executed: memory, disk space, etc. Complexity: How many resources your program needs to run: requirements, algorithm scale, etc. Complexity of course affects the performance, but performance cannot affect the complexity, so let's create the less complex code we can, but how can we determine the complexity of our code? easy, using the Big O notation. But there are multiple types of Big O, depending on what sentence or statement you are evaluating, it could be a simple if/else block or a function , depending on that we can say it is either linear or quadratic or maybe one of the following: No

Moving to Preact

Image
Hi Guys, It's been a while since I don't share with you cool stuff, so this is why I decided to take some time to introduce you to Preact. Basically Preact it's the same as React, it's a library which help us to manipulate the virtual DOM in the same way React does, but most important thing is that it's under the MIT license. Why is this so important? Well I don't want to make a big deal about it, but some time Ago the Apache Software Foundation made some changes to the the BSD + Patents license which is the React's license (more over is the License Facebook uses for all its projects) basically that change implies that if you compete with facebook your React (or any other facebook framework you use) your license will be terminated. You can read more about this change in this thread or this post (and this is the official announcement from Facebook which tell us that they're going to stick with their current lincense), because I don't want to

Use the conditionals properly in JS

Hi Guys, I know I haven't been writting too much (none I guess) I'm sorry for that, but I've been learning new stuff :D Today I want to share with you how to take advantage of the conditionals in JS, but first we need to understand how they work: //OR You might know that in JS the OR operator is represented by double pipes: || but, is it really returning a boolean value? well, the answer to that question is...NO, JS uses type conversion, it converts a type to boolean but just in certain contexts, take the following code snippet as example: Basically the OR operator seeks for a truly value from left to right, once it found it, it returns that value, if the conditional is used on a loop/conditional context, then JS will evaluate its truly value, if not, it will evaluate the real value. //AND The AND operator ( && ) it's used to evalue a truly condition, but I guess you already know that, and knowing how JS evaluates the conditionals depending on th

TECH-COFFEE - React the right way - Theory

Hi guys, I've been working with React lately and I found it very interesting, but, what's the right way to use React? Well, I read a lot of blogs, posts, tweets, etc. and I decided to share with you my experience. But first, we need to understand React, its lifecycle, the best architectural pattern to use, etc. Understand the theory first: If you have any question or concern, please let me know :) See you guys ^_^/

Currying Nowadays - Inheritance - Javascript

//English Hi Guys! sorry I've been too busy at work. I will do my best to keep writing about how cool JS is and the things you can do ;) Now, as you could see on my previous post , currying has evolved due to Function.prototype.bind . The purpose of this post is to see another example that's practical: "Inheritance" using currying! Imagine this scenario: The world has countries, a country has people. people could either be female or male and each person has a name, in JS, you could write a function like the following: function person(country,sex, name){ return 'Hello my Name is ' + name + ', I am a ' + sex + ' and I am from ' + country; } It looks easy but It will be hard to read and to maintain: function person(country,sex, name){ return 'Hello my Name is ' + name + ', I am a ' + sex + ' and I am from ' + country; } var pedro = person( 'Mexico' , '

Currying Nowadays - Javascript

Image
//Currying is evolving! <!-- English --> Hi guys, It's been a while since the last time I wrote, sorry  for that, anyways, today's post is about currying, if you don't know what is currying about, don't worry, take a look of my previous post (I strongly recommend you to read it if you don't know what currying is about), if you do, you can continue reading. Well it looks like you want to go on...so let´s start; When we say currying in js, you usually think in something like this: function Parent(){ return function Child(){ //Your code } } Well that´s how we used to do currying, now there´s a different way to do it, thanks to Function.prototype.bind() , let´s see how the function we have above can be easily replaced for the following code: function Parent(){ //Your code } var Child = Parent.bind( null ); NOTE: Maybe you'll be curious about the null we passed, well basically we're going to tell to th