Welcome back to another video. A couple of days ago I was with a friend of mine that is currently doing an internship at one of the big banks here in Canada. And we were looking over some code that his manager wanted him to optimize.
Late Bloomers by Rich Karlgaard: https://amzn.to/2DcmCLo
Disclaimer, this is an affiliate link
The code was interacting with Apache Spark and was using too much memory (500,000 entries).
After taking a look at the code with no knowledge of Spark, I proposed they use an iterator to reduce unnecessary data copying.
My friend looked at me like I was speaking a different language.
So I will be talking about what iterators are, their advantages, why they aren’t used more and finally go through my solution with you.
Iterators are an abstraction over iterations. For example, traditionally, if we wanted to go through all the elements in an array one by one, we would have an index that goes from 0 to length - 1. Then we would access the array elements using it.
But this makes the code a little more complicated than it needs to be; if we only want the element and not the index, then the index is unnecessary. Iterators allow us to just access the elements.
Now at first, that doesn’t seem very useful. And you’re right.
But when the data structure gets more complex, say a hashmap and you need to traverse all the keys.
The keys could be stored in a binary tree, in which case you will need to create your own traversal algorithm to get all the keys. With iterators, all that is done for you and all you need to do is loop over it with a for loop.
Another solution to this is that you can do the traversal and store the keys in an array. The problem with this approach is that it takes up additional memory; we now have 2 copies of our keys. Iterators on the other hand, does not do any copying, and only goes over the keys one by one.
The last thing is iterators work really well with functional programming features, such as map, reduce, filter, fold, etc. These tools reduce the amount of loops and edge cases you need to code out yourself, saving you time and headaches.
So if there are all these advantages, why are they not used very often?
The first reason I think, is because its not taught extensively in school. Professors rarely go over iterators in detail because a for loop or traversal algorithm will work. And they probably want you to use those traversal algorithms that is being taught instead of using code that’s already built for you. So the most you’ll use in school are probably elemental for loops. Unless you take a course on functional programming where they teach you Haskell.
The second reason is because many languages being taught does not support iterators very well. Some popular languages taught in school are Python, Java and C. Python being used to introduce students to programming. Java being used to introduce OOP to students. And C being used to introduce systems programming and memory management.
Out of these, only Python’s iterators are easy to pick up and use on the fly. C does not have any facilities for iterators unless you make your own.
Java iterators are very lacking in features. And with the release of Java 8 in 2014, developers can finally use functional programming features with Java streams. But stream’s ergonomics are still poor; being added so late to the language, switching between streams and iterators can be non-trivial, which discourage developers from using them and just use a for loop instead.
Just take Rust iterators:
Hope you enjoyed the video!
Apricity by lukrembo
Michikusa by PeriTune (Licensed under https://creativecommons.org/licenses/by/4.0/)
#iterators #apache spark
Can you use WordPress for anything other than blogging? To your surprise, yes. WordPress is more than just a blogging tool, and it has helped thousands of websites and web applications to thrive. The use of WordPress powers around 40% of online projects, and today in our blog, we would visit some amazing uses of WordPress other than blogging.
What Is The Use Of WordPress?
WordPress is the most popular website platform in the world. It is the first choice of businesses that want to set a feature-rich and dynamic Content Management System. So, if you ask what WordPress is used for, the answer is – everything. It is a super-flexible, feature-rich and secure platform that offers everything to build unique websites and applications. Let’s start knowing them:
1. Multiple Websites Under A Single Installation
WordPress Multisite allows you to develop multiple sites from a single WordPress installation. You can download WordPress and start building websites you want to launch under a single server. Literally speaking, you can handle hundreds of sites from one single dashboard, which now needs applause.
It is a highly efficient platform that allows you to easily run several websites under the same login credentials. One of the best things about WordPress is the themes it has to offer. You can simply download them and plugin for various sites and save space on sites without losing their speed.
2. WordPress Social Network
WordPress can be used for high-end projects such as Social Media Network. If you don’t have the money and patience to hire a coder and invest months in building a feature-rich social media site, go for WordPress. It is one of the most amazing uses of WordPress. Its stunning CMS is unbeatable. And you can build sites as good as Facebook or Reddit etc. It can just make the process a lot easier.
To set up a social media network, you would have to download a WordPress Plugin called BuddyPress. It would allow you to connect a community page with ease and would provide all the necessary features of a community or social media. It has direct messaging, activity stream, user groups, extended profiles, and so much more. You just have to download and configure it.
If BuddyPress doesn’t meet all your needs, don’t give up on your dreams. You can try out WP Symposium or PeepSo. There are also several themes you can use to build a social network.
3. Create A Forum For Your Brand’s Community
Communities are very important for your business. They help you stay in constant connection with your users and consumers. And allow you to turn them into a loyal customer base. Meanwhile, there are many good technologies that can be used for building a community page – the good old WordPress is still the best.
It is the best community development technology. If you want to build your online community, you need to consider all the amazing features you get with WordPress. Plugins such as BB Press is an open-source, template-driven PHP/ MySQL forum software. It is very simple and doesn’t hamper the experience of the website.
Other tools such as wpFoRo and Asgaros Forum are equally good for creating a community blog. They are lightweight tools that are easy to manage and integrate with your WordPress site easily. However, there is only one tiny problem; you need to have some technical knowledge to build a WordPress Community blog page.
Since we gave you a problem in the previous section, we would also give you a perfect solution for it. You might not know to code, but you have shortcodes. Shortcodes help you execute functions without having to code. It is an easy way to build an amazing website, add new features, customize plugins easily. They are short lines of code, and rather than memorizing multiple lines; you can have zero technical knowledge and start building a feature-rich website or application.
There are also plugins like Shortcoder, Shortcodes Ultimate, and the Basics available on WordPress that can be used, and you would not even have to remember the shortcodes.
5. Build Online Stores
If you still think about why to use WordPress, use it to build an online store. You can start selling your goods online and start selling. It is an affordable technology that helps you build a feature-rich eCommerce store with WordPress.
WooCommerce is an extension of WordPress and is one of the most used eCommerce solutions. WooCommerce holds a 28% share of the global market and is one of the best ways to set up an online store. It allows you to build user-friendly and professional online stores and has thousands of free and paid extensions. Moreover as an open-source platform, and you don’t have to pay for the license.
Apart from WooCommerce, there are Easy Digital Downloads, iThemes Exchange, Shopify eCommerce plugin, and so much more available.
6. Security Features
WordPress takes security very seriously. It offers tons of external solutions that help you in safeguarding your WordPress site. While there is no way to ensure 100% security, it provides regular updates with security patches and provides several plugins to help with backups, two-factor authorization, and more.
By choosing hosting providers like WP Engine, you can improve the security of the website. It helps in threat detection, manage patching and updates, and internal security audits for the customers, and so much more.
#use of wordpress #use wordpress for business website #use wordpress for website #what is use of wordpress #why use wordpress #why use wordpress to build a website
An iterator is a new concept of ES6. An Iterator is an object that lets us iterate through an Array, an Object, a String, or even custom Objects.
The Iterator allows us to effectively loop over a collection of objects like an array, string, objects, or other data structures.
In this article, we are going to talk about Itrables and how it uses the iterator to access the elements sequentially.
It’s a **collection, **A collection of values, or “elements”, that can be accessed sequentially each element at a time.
_For Example, _
Set classes are both
Iterable, as are most classes in the
Each element of the iterable is accessed by getting an Iterator using the iterator getter and using it to step through the values. Stepping with the iterator is done by calling Iterator.moveNext, and if the call returns
true, the iterator has now moved to the next element, which is then available as Iterator.current. If the call returns
false, there are no more elements.
We can also iterate over the elements of an
Iterable using the for-in loop construct, which uses the
iterator getter behind the scenes.
For example, you can iterate over all of the keys of a Map, because
Map keys are iterable.
Note:_ Although Map doesn’t implement Iterable, you can get Iterables from it using the Map
Besides being able to use them with a
for-in loop, an iterable gives you access to lots of other features.
For example, Because of some methods available, such as
_Iterable_class provides two methods that you can use to verify conditions:
_any()_: Returns true if at least one element satisfies the condition.
_every()_: Returns true if all elements satisfy the condition.
#iterables #dart #collection #iterators #lists
While writing an article about Generators, I realized that though iteration, iterable and iterator are so commonly used in programming; there is a certain degree of confusion around them. It’s crucial to understand the underlying concept for a better implementation. This is going to be a short and quick article to help us determine what is an iterable and what is an iterator.
#iteration #python #data-science #programming #iterators
Okay, you might be wondering, what even are iterators and iterable objects? An iterable is a sequential data structure that can be iterated over. Iterables can also have their own access method, which defines its iterator. This allows iterables to be publicly accessible. An iteratoris like a pointer that traverses the collection in a particular way. As we will get into in a bit, these new custom iterators in ES6 can loop through more than just a simple array.
This is a lot of jargon that I will break down in a few minutes with an example. But for starters, let’s take a look at the default use of ES6 iterators in the for-of loop.
In ES5 and before, we’re used to seeing for and while loops to iterate over arrays or strings. Now, with ES6, we can hop around an array or a string without having to set the parameters for these loops. The for-of loop by default knows how to iterate over these data types sequentially: