As a beginning coder, you’ve likely heard that Python is known as one of the easiest programming languages to learn. It has a number of web frameworks to help you build functional and scalable websites and applications. Django and Flask...
The functionality of a website depends on two vital areas — the front-end and the back-end. Three categories of developers — the front-end, back-end, and full-stack developers — operate these areas to create sleek, professional websites and applications. From 2020...
When we talk about code quality, we can think of different aspects of it. We mainly refer to the attributes and characteristics of code. While there is no widely adopted definition of high-quality code, we know some of the characteristics of good code:
Why Does Accessible Development Feel So Intimidating?
I’ve found accessible development to be one of the places where it’s easiest to fall into analysis paralysis: there’s always something that you feel like you need to double-check first, something that you heard someone else is doing, or just a vague feeling that you don’t really know enough yet to start tackling accessible coding yourself. Just one more blog, one more conference talk, one more video, and then you’ll be ready to start writing accessible code.
Meanwhile, our applications – and more importantly, our users – are stuck with the same old inaccessible code that we just keep writing. The best thing we can do is to start writing accessible code to the best of our ability, with the acknowledgment that we might make a mistake! After all, isn’t that just how development works all the time? We code things using the skillset we have, adhering to the best practices that we’re aware of and the current web standards. Sometimes we make mistakes, whether those are bugs or architecture approaches we would have done differently in hindsight, but we still ship an application that’s (hopefully) mostly functional. Accessibility is the same way: it functions on a sliding scale, not an on/off switch. We code accessible features as we’re able, based on what we know right now and the current accessibility-related guidance. It might not be perfect 100% of the time, but anything is better than ignoring accessibility entirely. And hey, code isn’t carved into stone, right? You can always go back and update something once you’ve learned how to do it better.
Working with Docker containers allows developers to create encapsulated applications that are independent of the host machine and contain all the necessary libraries and dependencies. In practice, docker-compose is often used to configure and manage containers. When several containers are built in a docker-compose file, they are automatically connected to a common network (which is created by default) and can communicate with each other.
In most cases, however, each project will have its own docker-compose file. In such configurations, the containers from one docker-compose will not be able to connect to those from the other unless we have previously created and configured a shared network. In such cases, it is necessary to use a docker networking in compose. In this article, we’ll take a look at a sample method/example, how to set up networks in different docker-compose files, so that individual projects and the containers/services in them can be connected in a single network when running on a local machine.
Good design is invisible! It’s like an air conditioner set on automatic temperature control. Until you feel too hot or cold, you don’t pay any attention to it, concentrating instead on the task at hand, or just enjoying your time.
For users surfing the web, Ajax is like an automatic air conditioner. It makes websites smoother and faster to use, resulting in a pleasurable experience. And most importantly, it just works!
Ajax is a web development technique that stands for Asynchronous JavaScript And XML. It’s used to create dynamic web applications that are interactive and fun. With Ajax, you don’t have to wait for the web page to reload to see a change. Everything’s taken care of automatically in the background without disrupting what you’re doing, thereby enhancing your user experience.
Ajax at work!
You’ve probably come across Ajax on the web already. Google Search’s autocomplete feature is perhaps the most popular one. Google Maps is another. Live refresh of tweets, Facebook comments, Reddit posts, YouTube likes, all these incredible user experiences are made possible thanks to Ajax and related technologies.
In this post, I’ll give you a quick intro to Ajax, list its advantages, explain how it works in WordPress, and then we’ll dive headfirst into creating a simple WordPress Ajax Plugin.
Sounds fun? Let’s get started.
The Basics of Ajax
Ajax uses a combination of programming languages such as HTML/CSS, JavaScript, XML/JSON, and a server-side scripting language (PHP, ASP.NET, etc.). It works by sending data from the browser to the server, which processes it and sends back a response. This response is used by the browser to update the web page without reloading it.
Here’s how it usually goes:
A user action triggers an event in a browser (like a button click).
The Ajax call activates, which sends a request to the server, using XML/JSON.
The server-side script processes this request. It can also access the database if it needs to.
The server then sends a response back to the browser.
A second JavaScript function, called a callback function, receives the response and updates the web page.
The Many Advantages of Ajax
Minimizes bandwidth usage and optimizes network operations, as the servers won’t be required to process loads of data.
Saves time for both the users and the server, as the user can see the response from the server immediately.
Increased performance. Since no full-page data is being sent, Ajax improves the performance, speed, and usability of web pages/apps.
Increased responsiveness. By eliminating full-page reload, websites will be swifter and highly responsive, thus more user-friendly.
Skills Needed to Work with Ajax in WordPress
Knowledge of HTML, CSS, and JavaScript (jQuery is enough)
Basic familiarity with XML or JSON data interchange formats
Know-how of PHP for server-side scripting
If your jQuery or PHP knowledge is touch and go, don’t fret! You can still follow the tutorial logic. Feel free to hop into the comments section if you’re stuck or need help with something :)
Intro to Ajax in WordPress
The core of WordPress already uses Ajax, but only in the admin screens. For instance, when you’re moderating comments or adding/deleting items from categories or posts, you can see instant updates thanks to Ajax. It’s also the tech behind the much loved auto-save functionality.
Ajax is most commonly used with jQuery functions on WordPress, as it’s much simpler when compared to VanillaJS. Moreover, WordPress core already comes loaded with the jQuery library.
Here’s what the process for using Ajax in WordPress looks like:
The user triggers an Ajax request, which is first passed to the admin-ajax.php file in the wp-admin folder.
The Ajax request needs to supply at least one piece of data (using the GET or POST method). This request is called the action.
The code in admin-ajax.php uses the action to create two hooks: wp_ajax_youraction and wp_ajax_nopriv_youraction. Here, youraction is the value of the GET or POST variable action.
The first hook wp_ajax_youraction executes only for logged-in users, while the second hook wp_ajax_nopriv_youraction caters exclusively for logged-out users. If you want to target all users, you need to fire them both separately.
Plan the hook functions for graceful degradation. It ensures that your code will work even on browsers with JavaScript disabled.
Let’s Create a WordPress Ajax Plugin
Every great journey begins with a single step, and so does our learning. Let us build a basic WordPress plugin called Post Likes Counter with the following features:
Logged-in users can like posts.
The plugin keeps a tally of the total number of post likes and displays them.
The post likes counter is updated instantaneously on the front-end.
Logged-out users will be shown an error message if they attempt to like a post.
After that, you need to find your theme’s single.php post template. It’s used when a single post is queried, which is where we want our post likes counter to be. This file can be found in the root folder of your active theme. Keep it open for editing.
Get the Post Template Ready for an Ajax Call
Let’s create a link here to let users like posts. If a user has JavaScript enabled, it’ll use the JavaScript file we’ll create later; if not, it’ll just follow the link directly. Place the code given below in your single.php file.
Alternatively, you can add this code to any of the template parts your single.php file includes. For instance, if you’re using the official Twenty Nineteen theme, you can insert this code in your theme’s content-single.php file. For testing this plugin code, I inserted it in this file at the very end of its div.entry-content section.
Addressing the Ajax Call Without JavaScript
Clicking the link created above will take you to the admin-ajax.php script, but you won’t see any useful output as you’ve not created any function yet to run your action.
To do that, create a function in your plugin file and add it to the two hooks that were created by WordPress for you. Follow the code shown below:
If everything checks out, when a logged-in user clicks the Like this Post link, the like counter above it should increase by 1 automatically. For browsers with JavaScript disabled, the page will refresh, but it’ll still show the updated like count.
The function to handle logged-out users doesn’t do much here except for throwing up an error message. It’s only meant to serve as an example. You can, of course, build on this and give your visitors more helpful options.
Finally, Adding Support for JavaScript
It’s a good practice to add support for JavaScript towards the end, as it makes things much clearer. To use Ajax on WordPress, you need to enqueue jQuery library as well as your plugin’s custom JavaScript file. For this, go to your plugin and append the following script:
Once that’s done, it’s time to create the liker_script.js JavaScript file. Then you have to upload this file to the location referenced in the previous code (hint: it’s your plugin’s root folder). Here’s the code for liker_script.js:
The my_user_like() function defined in our plugin should send our browser a response as a JSON-encoded result array, which can also be used as a JavaScript object. Using this, we can update the post like count without reloading the web page.
And that’s it! Hurrayyyyyy!
You’ve now enabled Ajax functionality for your plugin. Of course, you can expand on this and add more features as per your liking. Go ahead, tweak it till you make it!
Our simple post like counter. You can add styles, animations, and other scripts to level it up.
Notable WordPress Plugins Which Use Ajax
Need some Ajax inspiration to fire you up? Check out these amazing WordPress plugins that use the power of Ajax to build powerful features and smoother user experiences.
Lazy Load Plugins
Lazy Loading is a web development technique used to improve initial page loading time. It’s done by delaying the loading of resource-heavy assets that aren’t visible to the user in their browser’s viewport. These assets are loaded automatically when the user scrolls down the web page. The free version of Smush supports lazy loading.
Forminator
A completely expandable form maker plugin that also supports polls, quizzes, order forms with payment options, etc. It has an option to enable form submissions with Ajax, making it a seamless experience for the users.
Login With Ajax
Power your WordPress site with smooth Ajax login and registration effects with this feature-rich plugin. If you’re looking to give your users a better login and registration experience than the default WordPress one, look no further.
WP-PostRatings
This simple plugin adds an Ajax rating system for your WordPress website’s posts and pages. It also adds shortcode support for the ratings, so that you can display them anywhere you want.
YITH WooCommerce Ajax Product Filter
An extremely helpful and powerful plugin for WooCommerce that lets you apply the exact filters you need to display the product variations you’re looking for. Ajax makes sure that it all happens in a jiffy.
Ajax Search Lite
A responsive, live search plugin for WordPress, powered by Ajax. It also includes Google autocomplete and keyword suggestions. Give your users a better search experience on your website with this plugin.
Simple Ajax Chat
Have you ever wondered if you could chat with other users on a website, live? This Ajax-powered plugin is the answer to that. It’s mobile compatible and is built to be extremely customizable as per your liking.
What’s good for the <body> is good for the user and server too, but you need to balance it out. Ajax is a powerful tool in your arsenal to enhance website performance and user experience. But you should only use it where it’s necessary. Always focus on the user experience aspect. It’ll be a bit rough in the beginning, but once you’ve mastered the basics of Ajax, there’s no stopping you!
Today, we discuss C# code quality and a variety of errors by the example of CMS DotNetNuke. We're going to dig into its source code. You're going to need a cup of coffee...
DotNetNuke
DotNetNuke is an open-source content management system (CMS) written mainly in C#. The source code is available on GitHub. The project is part of the .NET Foundation.
The purpose of the following websites is to help you test to what extent your programming prowess is able to solve problems low to high. Not only that, but there you also have to compete with other developers to achieve higher rankings. Just like playing games, we have to go from low rankings like copper, silver to gold, platinum. Here are some websites to help increase your interest in programming.
Exercism
The Exercism website is home to thousands of exercises that you can practice in over 50 supported programming languages. Its exercises are also varied for beginners or those with a lot of programming experience. It is open-source and based on donations from developers around the world so you can rest assured that it won't be charged. In addition, if you feel you are capable, you can also contribute helpful exercises to the community that will improve your programming skills and others.
We know that, in a software project, nothing replaces good documentation. However, it is also necessary to pay attention to how intuitive the written code is. After all, the simpler and more natural the code is, the better its experience for users.
In the simple "programming rule", in which we will forget everything we have to remember, an API that "forces" you to remember is crucial proof of failure.
Currently the most popular version control system is git and I'll be writing this based on git and it's functionalities and capabilities.
Git is often seen as a way to enable distributed programming i.e. multiple programmers can work on the same code repository quite easily without disturbing each others work (much). In addition to that just like other VCS's it's also a log of work but to my experience that part is often unfortunately neglected. What I will be focusing this time is the log part because I think it deserves more attention.
Why to create a meaningful log?
The git log should consist from small meaningful changesets where each commit addresses a single problem. By dividing the log to small commits it enables resilient way of working. Being resilient enables simple and fast procedures to rollbacks, reviews, tags, branching etc.
Lets say that a developer is implementing a REST API. The API needs a web layer that receives the HTTP requests, it probably has some sort of logic layer to do data transformations and validations and maybe some calculations and finally it has a data storage where the data is persisted. There are options how to record this work to the log. One option would be to implement the API and record a single commit or squash the commits before pushing the changes to remote so it would become a single commit. Another option would be to record commits every now and then while developing and finally push those commits as is to the remote repository. Yet another way would be to carefully pick what is recorded per commit in order to have a set of meaningful commits that each address a single issue.
Example of the first approach would be something like this:
Acceptance tests are a great tool to verify that the application or system works as expected from end to end. Sometimes these tests can be called end-to-end tests but sometimes end-to-end tests have a different meaning. Another term to describe the same functionality is QA tests and a subset of acceptance tests is often referred to as smoke tests.
The Idea
The idea is to define input and the expected output and once the system and all its dependant services are running the whole system can be verified to work as expected. In an ideal world, the acceptance tests would be implemented based on the acceptance criteria of the use case.
You must have heard about engineers doing coding in their systems, but what does it mean? It is an act of writing a language that can be understood by the computers, which let them perform a task. Codes are compiled and executed to let the process happen. We can create apps, software, websites with the help of coding. Codes are written in a different domain, for example, a machine learning engineer will write code for their ML models. A full-stack developer will write code to optimize their website, and an android developer will write code to make android applications. Coding can also be referred to like computer programming.
Why Should I Learn to Code?
Coding lets you decode your future easily. It opens new opportunities for the future. It not only improves your problem-solving skills but also helps in fulfilling your dream of getting the highest-paid jobs.
Live Server allows you to see code changes reflected in the browser. It launches a local development server with a live reload feature both for static and dynamic pages.
Every time you save your code, you'll instantly see the changes reflected in the browser. You'll be much faster at spotting errors and it's much easier to do some quick experiments with your code.
Unit tests are the developer's number one safety net. Let that sink in. This is the number one reason for writing unit tests.
Unit tests are written by developers for developers to ensure that the code works as expected and handles happy and sad paths correctly. With enough unit test coverage, the tests enable a safe environment for refactoring and rewriting code.
Immutability is a special thing that in my mind deserves a short explanation and praise. If you're familiar with functional programming you surely recognize the concept of immutability because it's a key ingredient of the paradigm. In the world of object-oriented programming, it's not as used and as easy to use approach but there are ways to incorporate immutability to parts of the code and I strongly suggest you do so too.
Quick Intro to Immutability
The basic idea of immutability is unchangeable data.
Google is a titan of technology with one of the largest codebases in the world. Managing and scaling this amount of code is a monumental task. And while Google doesn't profess to have all the answers, you can probably learn a thing or two from their journey.
In the first episode of a two-part series, Senior Google Staff Engineers Hyrum Wright and Titus Winters joined me on the Dev Interrupted podcast to discuss lessons learned from programming at Google and to talk about their new book.
Modern businesses run on code - and ensuring code quality is crucial to success. To get the inside scoop on Quality Assurance (QA), I talked with Erika Chestnut, Head of QA at Calendly at what you need to do to set up QA that works for your business needs, how to socialize the right values for your team, what not to do, and how to adapt these processes when necessary.
Arthur Linum is a technology consultant. He shared some of his experiences with me:
—I was the consultant for a startup that had accumulated substantial technical debt. They had rushed to meet tight deadlines to position themselves at the forefront of the market, and this had led to code that was quick and dirty.