The Wonders of Getters & Setters in JS
Okay with the assumption that you are a ” something that reference newbie” and be aware I am probably two years in the game and just now understanding this behind javascript.
So as you may already know ‘Getters’ and ‘Setters’ are common archetypal methods in several other programming languages, specifically more within object-oriented languages like C#, Java, and Objective- C. Solet go ahead and dig right into it.
In most object-oriented languages, ‘Getters’ and ‘Setters’ refer to the properties of a given object. Getters are methods that return the value of that property, and as you may assume setters set them. Now Javascript has many object-oriented features, and this taps into some of those.
The reason they’re a thing and why they exist is a lot more clear in other languages in my personal opinion. So I will go on a tangent briefly so you can understand what I mean and the language of my choice will be Java. Okay, so let’s assume that you want to make some cars. To do that, in java we need a class called “Cars”
class Car {
private int year;
private string make;
private string model;
private string vin;
private string color;
}
To make a car, we’d do this
//create a new car that will be called infiniti
Car infiniti = new Car();
A result, since Infiniti is a car and we said that Cars have a year and a make, we know Infiniti has these.
Don’t worry I will each the code snippet stated above, take note of the word private? That means that only Infiniti knows its year and its make and most importantly, it’s own vin. What this means is that Java, the following would not run and would fail:
CarJacker someRandomThief = new CarJacker();
someRandomThief.attemptingToGetVin(infiniti.vin);
In JS, you can do that –access the property directly through the dot operator. Now, why on the earth would you want that in a language? Because it makes things easier to maintain, it makes code safer and of course cleaner in the long run. When those properties are private, you can prevent other parts of a program you’re writing from accidentally changing them and weird bugs from showing up. this protecting of properties from outside objects is called encapsulation and is hugely important in OOP. Some would consider this a great feature but it can also be super annoying, because how often do we have variables that we never want any other part of the program to access?
Finally entering into the fray are ‘Getters’ and ‘Setters’. Commonly in Java and other languages as stated before getters and setters methods which allow “outsiders” to access those properties.
class Car {
private int year;
private string make;
private string model;
private string vin;
private string color;
public string getVinNumber() {
//this method returns the vin number of the car
return vin;
}
public void setVinNumber(string newVinCreated) {
//'this' refers to the object itself --Infiniti, etc
this.vin = newVinCreated;
}
}
As a result, outside objects can now interact! So if our car thief got lucky, it could instead:
CarJacker someRandomThief = new CarJacker();
//now we just stole a new car
someRandomThief.attemptingToGetVin(infiniti.getVinNumber());
Now in Java, and the other languages that I know of, ‘getter’ and ‘setter’ are common but not formal: ie, I could call getVinNumber() something as unrelated as UnlessMethodName() and it would still work–but would just be a note helpful name.
I know this was much longer than some of my other posts but it all has a purpose of course. Now within the js you have “get” and “set” doing those things because of the OOP idea of encapsulation and getters and setters, which is a useful idea–and sort of a hard sell in particular in js, where it’s not enforced because you don’t have to declare whether something is private, so it becomes a sort of arbitrary weird layer unless you understand the original intended purpose.
Ultimately the pattern behind is a thing I dislike about JavaScript — and I’ll be as honest as I can be, I’ve read that documentation so many times before, and even again as I was preparing this post and without much it still makes very little sense to me, and I’ve had a lot more experience since the first time I read it along with a hunk of object-oriented under my belt… and it still is really hard to follow.
In short, get latest() is a means of having things happen when you want the value of latest, and enables that to happen–since you have to have a function or method for things to happen–while still letting you skip the “()” because it’s single value representing a property.
- JS has a prototypical inheritance, not class-based. Which is far from the only difference, but a huge one.
- As with everything, there are differences of opinion and you can still have crazy OOP code, it’s not perfect but that’s the intended purpose.
- I strongly feel that stuff like Raccoon raccoon = new Raccoon() leads too quickly to semantic satiation and can lead to more bugs and always go for more specific or least different variable names when I can, but anyways.
- Published in blog, Javascript, Like I Am Five
UMD & ESM… What the heck is this?
In the beginning, JS did not have a way to import/export modules. This was a problem for many developers and if you don’t believe then picture this. You’re writing an app in just a single file, I know I know it would be a nightmare.
So as time progress, people of higher intellect than myself attempted to add modularity to javascript. The ones that shouldn’t surprise you is UMD and ESM but there are others of course like CommonJS, Native JS and AMD. There are several others but the two from above are considered some of the big players
I am going to tackle some brief information like syntax, purpose and common behaviors. My goal is to help others that may be confused when dealing with particular issues with modules.
UMD
Universal Module Definition or as referenced UMD.
– Works on front and back end (hence the name universal).
– Unlike the other modules, UMD is more like a pattern to configure several module systems. Check out other patterns
– UMD is usually used as a fallback module when using bundler like rollup/Webpack
(function (root, factory) {
if (typeof define === "function" && define.amd) {
define(["jquery", "underscore"], factory);
} else if (typeof exports == "object") {
module.exports = factory(require("jquery"), require("underscore"));
} else {
root.Requester = factory(root.$, root._);}}(this, function ($,_) { //this is where I defined my module implementation var Requester = {//...};
return Requester;}));
ESM
ES Module short as ESM. It is javascript’s proposal to implement as standard module system. I am sure many of you have seen this: import React from 'react'
- Works in many modern browsers
- Tree-shakeable, due to ES6’s static module structure
- ESM allows bundlers like rollup to remove unnecessary code, allowing sites to ship less code to get faster load
- can be called in HTML
<script type="module"> import {func1} from 'my-lib';
func1(); </script>
Summary
– ESM is the best module format thanks to its simple syntax, async nature, and tree-shakeability.
– UMD works everywhere and usually used as a fallback in case ESM does not work
Thanks for reading, devs! In the future, I plan to write in depth about each module, especially ESM because it is packed with many awesomeness.
- Published in blog, Javascript
Machine Learning w/ eCommerce
We hear a lot about Machine Learning these days as it has become one of the hottest buzzwords around. However, we are approached by many people who don’t seem to have a clear idea on how it could be applied to add value to their business. Since it is a very broad topic with different types of applications based on the desired goals and objectives, we aim to create a series of blog posts, each targeting a different industry, and just touch on some of the different ways in which Machine Learning can help add value to a business within that particular industry. Today, we’ll start with eCommerce, as it is one of the low hanging fruits that can quickly be picked for enhancement via Machine Learning.
What kind of Machine Learning is applicable in eCommerce?
Machine Learning comes in several different forms such as Supervised Learning, Unsupervised Learning, Semi-Supervised Learning and Reinforced Learning. The scope of this blog won’t delve into the technical details, but we’ll just preface our eCommerce based solutions discussion with the information that while Machine Learning can be used to do things like drive cars, perform facial recognition, or identify a car’s license plate from CCTV footage, what we aim to do in our eCommerce implementation is to be able to identify user behavior patterns to perform predictive analysis and make proactive decisions driven by data. We’ll explain in further detail.
Recommendation Engine
Perhaps one of the biggest reasons why Amazon was able to demolish all its opponents in the eCommerce industry is/was largely due to their incredible recommendation engine which is entirely based on Machine Learning. A recommendation engine takes in past user behavior analytics information as training data and learns the different patterns and trends. After ingesting millions upon millions of records of these purchasing habits of users, along with their profiles (Supervised Learning), the system will be able to predict how a new user may end up browsing the website, or what products they may be interested in, based on their browsing habits, the items in the cart, and what people with a similar profile have done in the past. When the user completes their transaction, the recommendation will take into account if its recommendations were successful or not, and further improve its algorithm (Reinforced Learning).
A Recommendation Engine is similar to the rack you find during checkout at the grocery store (usually contains candy, gum, magazines, etc.). It is an opportunity to remind the shopper of an item that they may want/need but had forgotten about, or to entice them to buy something they weren’t even planning on buying in the first place. The more accurate these recommendations are to the shopper’s wants & needs, the more likely they are to purchase additional items.
Price Optimization
Another area in which Machine Learning is providing a great deal of assistance to the business team is in Price Optimization. Prices for products can fluctuate a great deal depending on dozens—if not hundreds—of variables. A pricing engine can be created to take into account a great deal of information from the shopper’s profile, current trends, competitor prices, product abandonment rates, and much more, and determine what percentage discount to offer the shopper on a specific product in order to increase the potential of making the sale, while keeping a healthy profit margin on the product. When dealing with a catalog of hundreds of millions of products & variants, with hundreds of factors going into pricing each one of them, you can see how quickly it can become infeasible for humans to do this task with full coverage. By utilizing Machine Learning to optimize pricing on a catalog of products, eCommerce stores can unlock a massive competitive advantage.
Retargeting, Discounts & Upsells
A shopper may not always complete the purchase. They may browse for a while, even add items to their cart, and eventually leave without completing the transaction. Machine Learning can help add value here as well. Retargeting campaigns can be executed to reach out to previous customers who have bought, abandoned a cart, or just browsed your website. These campaigns can be supercharged with Machine Learning by looking at historic data of similar shopper profiles and how they may have been converted in the past via retargeting. In some cases, Facebook or Instagram ads may have worked. In other cases, offering a discount valid for 24 hours on the products in their abandoned cart may have worked. It all depends on what the data is telling you, and that is where Machine Learning shines. As it is already analyzing hundreds of millions of past shoppers’ habits and outcomes, it will be able to predict what is most likely to work when attempting to convert a potential customer with similar habits & profile details.
Conclusion
These are just a few tips and tricks that are being used by eCommerce giants such as Amazon and Walmart, and more stores are jumping onboard with this line of thinking (for obvious reasons). With the availability of tools such as Google’s AutoML, and similar offerings from Amazon, Microsoft and others, Machine Learning is no longer the scary black box it once was and there has never been a better time to climb onboard the Machine Learning train as it leaves the station. If you are interested in implementing Machine Learning to add value to your business, reach out to us and we’d be happy to discuss the different options that may be available to you.
- Published in blog, E-Commerce
Single Page VS. Multi-Page Application
Single Page App (SPA)
A single-page application and will refer to as (SPA) is an app that works inside a browser and does not require page reloading during use. You are using this type of applications every day. These are, for instance: Gmail, Google Maps, Facebook or GitHub.
SPAs are all about serving an outstanding UX by trying to imitate a “natural” environment in the browser — no page reloads, no extra wait time. It is just one web page that you visit which then loads all other content using JavaScript — which they heavily depend on.
Multiple Page App (MPA)
Multiple-page applications and will refer to as (MPA) work in a “traditional” way. Every change eg. display the data or submit data back to server requests rendering a new page from the server in the browser. These applications are large, bigger than SPAs because they need to be. Due to the amount of content, these applications have many levels of UI. Luckily, it’s not a problem anymore. Thanks to AJAX, we don’t have to worry that big and complex applications have to transfer a lot of data between server and browser. That solution improves and it allows to refresh only particular parts of the application. On the other hand, it adds more complexity and it is more difficult to develop than a single-page application.
Before Development
You need to consider the goal of the site and who you are targeting overall. If you know you need multiple categories (because, for instance, you run an online shop or publish a lot of other content) — use a multi-page site. If you are sure that your site is appropriate for a pure single-page experience — go for it. And if you like SPA but can just barely fit everything into a single page, consider the hybrid site instead. This is another way I haven’t mentioned before. A hybrid application takes what is the best in both approaches and try to minimize the disadvantages. It is, in fact, a single page application which uses URL anchors as synthetic pages enabling more in build browser navigation and preference functionality. But this is the topic for another article.
Possibly in the near future, everyone will use Single Page Application model (including a hybrid app), as it seems to bring a lot of advantages. Many apps on the market are migrating towards this model. However, as some projects simply cannot fit into SPA, the MPA model is still vivid.
- Published in Development, New Web Site, Web Application Development
What is Bitcoin? The Nitty and Gritty Guide
So the new topic that is raving all over within the news and around the water cooler is Bitcoins. Everyone wants to know what it is, how to use it and is it even worth it?
So to start the definition that investor should be familiar is :
Bitcoin is a crytocurrency, a form of electronic cash.
It is a decentralized digital currency without a central bank or single adminstrator that can be sent from user to user on peer-to-peer bitcoin blockchanin network without the need for intermediaries.
I will explain how the system works, how you can use it for your profit, which scams to avoid. I will also direct you to resources that will help you store and use your first pieces of digital currency.
Small wonder that Bitcoin emerged in 2008 just after Occupy Wall Street accused big banks of misusing borrowers’ money, duping clients, rigging the system, and charging boggling fees. Bitcoin pioneers wanted to put the seller in charge, eliminate the middleman, cancel interest fees, and make transactions transparent, to hack corruption and cut fees. They created a decentralized system, where you could control your funds and know what was going on.
Bitcoin has come far in a relatively short time. All over the world, companies, from REEDS Jewelers, a large jewelry chain in the US, to a private hospital in Warsaw, Poland, accept its currency. Billion dollar businesses such as Dell, Expedia, PayPal, and Microsoft do, too. Websites promote it, publications such as Bitcoin Magazine publish its news, forums discuss cryptocurrency and trade its coins. It has its application programming interface (API), price index, and exchange rate.
Problems include thieves hacking accounts, high volatility, and transaction delays. On the other hand, people in third world countries may find Bitcoin their most reliable channel yet for giving or receiving money.
Key Highlights
- October 31, 2008: Bitcoin whitepaper published.
- January 3, 2009: The Genesis Block is mined.
- January 12, 2009: The first Bitcoin transaction.
- December 16, 2009: Version 0.2 is released.
- November 6, 2010: Market cap exceeds $1 million USD.
- October 2011: Bitcoin forks for the first time to create Litecoin.
- June 3, 2012: Block 181919 created with 1322 transactions. It is the largest block to-date.
- June 2012: Coinbase launches.
- September 27, 2012: Bitcoin Foundation is formed.
- February 7, 2014: Mt. Gox hack.
- June 2015: BitLicense gets established. This is one of the most significant cryptocurrency regulations.
- August 1, 2017: Bitcoin forks again to form Bitcoin Cash.
- August 23, 2017: SegWit gets activated.
- September 2017: China bans BTC trading.
- December 2017: First bitcoin futures contracts were launched by CBOE Global Markets (CBOE) and the Chicago Mercantile Exchange (CME).
- September 2018: Cryptocurrencies collapsed 80% from their peak in January 2018, making the 2018 cryptocurrency crash worse than the Dot-com bubble’s 78% collapse.
- November 15, 2018: Bitcoin’s market cap fell below $100 billion for the first time since October 2017.
- October 31, 2018: 10-year anniversary of Bitcoin.
Understanding Bitcoin – What is Bitcoin in-depth?
At its simplest, Bitcoin is either virtual currency or reference to the technology. You can make transactions by check, wiring, or cash. You can also use Bitcoin (or BTC), where you refer the purchaser to your signature, which is a long line of security code encrypted with 16 distinct symbols. The purchaser decodes the code with his smartphone to get your cryptocurrency. Put another way; cryptocurrency is an exchange of digital information that allows you to buy or sell goods and services.The transaction gains its security and trust by running on a peer-to-peer computer network that is similar to Skype, or BitTorrent, a file-sharing system.
Bitcoin Transactional properties:
1.) Irreversible: After confirmation, a transaction can‘t be reversed. By nobody. And nobody means nobody. Not you, not your bank, not the president of the United States, not Satoshi, not your miner. Nobody. If you send money, you send it. Period. No one can help you, if you sent your funds to a scammer or if a hacker stole them from your computer. There is no safety net.
2.) Pseudonymous: Neither transactions or accounts are connected to real-world identities. You receive Bitcoins on so-called addresses, which are randomly seeming chains of around 30 characters. While it is usually possible to analyze the transaction flow, it is not necessarily possible to connect the real world identity of users with those addresses.
3.) Fast and global: Transaction is propagated nearly instantly in the network and are confirmed in a couple of minutes. Since they happen in a global network of computers they are completely indifferent of your physical location. It doesn‘t matter if I send Bitcoin to my neighbor or to someone on the other side of the world.
4.) Secure: Bitcoin funds are locked in a public key cryptography system. Only the owner of the private key can send cryptocurrency. Strong cryptography and the magic of big numbers makes it impossible to break this scheme. A Bitcoin address is more secure than Fort Knox.
5.) Permissionless: You don‘t have to ask anybody to use cryptocurrency. It‘s just a software that everybody can download for free. After you installed it, you can receive and send Bitcoins or other cryptocurrencies. No one can prevent you. There is no gatekeeper.
Where can I find Bitcoins?
First, we would recommend you read this in-depth guide for buying Bitcoin.
You can get your first bitcoins from any of these four places.
- A cryptocurrency exchange where you can exchange ‘regular’ coins for bitcoins, or for satoshis, which are like the BTC-type of cents. Resources: Coinbase and Coinsquare in the US & Canada, and BitBargain UK and Bittylicious in the UK.
- A Bitcoin ATM (or cryptocurrency exchange) where you can change bitcoins or cash for another cryptocurrency. Resources: Your best bets are BTER and CoinCorner
- A classified service where you can find a seller who will help you trade bitcoins for cash. Resources: The definitive site is LocalBitcoins.
- You could sell a product or service for bitcoins. Resources: Sites like Purse.
Caution! Bitcoin is notorious for scams, so before using any service look for reviews from previous customers or post your questions on the Bitcoin forum.








