Web Design

Creating a Google Maps shortcode for WordPress
Creating a Google Maps shortcode for WordPress
about 1 hour ago
Tips for Beginners to Website Designing
Tips for Beginners to Website Designing
about 1 hour ago
Great design is a product of care and attention applied to areas that matter, resulting in a useful, understandable, and hopefully beautiful user interface. But don’t be fooled into thinking that design is left only for designers. The...
Great design is a product of care and attention applied to areas that matter, resulting in a useful, understandable, and hopefully beautiful user interface. But don’t be fooled into thinking that design is left only for designers. There is a lot of design in code, and I don’t mean code that builds the user interface—I mean the design of code. Well-designed code is much easier to maintain, optimize, and extend, making for more efficient developers. That means more focus and energy can be spent on building great things, which makes everyone happy—users, developers, and stakeholders. There are three high-level, language-agnostic aspects to code design that are particularly important. System architecture—The basic layout of the codebase. Rules that govern how various components, such as models, views, and controllers, interact with each other. Maintainability—How well can the code be improved and extended? Reusability—How reusable are the application’s components? How easily can each implementation of a component be customized? In looser languages, specifically JavaScript, it takes a bit of discipline to write well-designed code. The JavaScript environment is so forgiving that it’s easy to throw bits and pieces everywhere and still have things work. Establishing system architecture early (and sticking to it!) provides constraints to your codebase, ensuring consistency throughout. One approach I’m fond of consists of a tried-and-true software design pattern, the module pattern, whose extensible structure lends itself to a solid system architecture and a maintainable codebase. I like building modules within a jQuery plugin, which makes for beautiful reusability, provides robust options, and exposes a well-crafted API. Below, I’ll walk through how to craft your code into well-organized components that can be reused in projects to come. The module pattern There are a lot of design patterns out there, and equally as many resources on them. Addy Osmani wrote an amazing (free!) book on design patterns in JavaScript, which I highly recommend to developers of all levels. The module pattern is a simple structural foundation that can help keep your code clean and organized. A “module” is just a standard object literal containing methods and properties, and that simplicity is the best thing about this pattern: even someone unfamiliar with traditional software design patterns would be able to look at the code and instantly understand how it works. In applications that use this pattern, each component gets its own distinct module. For example, to build autocomplete functionality, you’d create a module for the textfield and a module for the results list. These two modules would work together, but the textfield code wouldn’t touch the results list code, and vice versa. That decoupling of components is why the module pattern is great for building solid system architecture. Relationships within the application are well-defined; anything related to the textfield is managed by the textfield module, not strewn throughout the codebase—resulting in clear code. Another benefit of module-based organization is that it is inherently maintainable. Modules can be improved and optimized independently without affecting any other part of the application. I used the module pattern for the basic structure of jPanelMenu, the jQuery plugin I built for off-canvas menu systems. I’ll use that as an example to illustrate the process of building a module. Building a module To begin, I define three methods and a property that are used to manage the interactions of the menu system. var jpm = { animated: true, openMenu: function( ) { … this.setMenuStyle( ); }, closeMenu: function( ) { … this.setMenuStyle( ); }, setMenuStyle: function( ) { … } }; The idea is to break down code into the smallest, most reusable bits possible. I could have written
about 2 hours ago
We’ve all been there: that bit of JavaScript functionality that started out as just a handful of lines grows to a dozen, then two dozen, then more. Along the way, a function picks up a few more arguments; a conditional picks up a few mor...
We’ve all been there: that bit of JavaScript functionality that started out as just a handful of lines grows to a dozen, then two dozen, then more. Along the way, a function picks up a few more arguments; a conditional picks up a few more conditions. And then one day, the bug report comes in: something’s broken, and it’s up to us to untangle the mess. As we ask our client-side code to take on more and more responsibilities—indeed, whole applications are living largely in the browser these days—two things are becoming clear. One, we can’t just point and click our way through testing that things are working as we expect; automated tests are key to having confidence in our code. Two, we’re probably going to have to change how we write our code in order to make it possible to write tests. Really, we need to change how we code? Yes—because even if we know that automated tests are a good thing, most of us are probably only able to write integration tests right now. Integration tests are valuable because they focus on how the pieces of an application work together, but what they don’t do is tell us whether individual units of functionality are behaving as expected. That’s where unit testing comes in. And we’ll have a very hard time writing unit tests until we start writing testable JavaScript. Unit vs. integration: what’s the difference? Writing integration tests is usually fairly straightforward: we simply write code that describes how a user interacts with our app, and what the user should expect to see as she does. Selenium is a popular tool for automating browsers. Capybara for Ruby makes it easy to talk to Selenium, and there are plenty of tools for other languages, too. Here’s an integration test for a portion of a search app: def test_search fill_in('q', :with => 'cat') find('.btn').click assert( find('#results li').has_content?('cat'), 'Search results are shown' ) assert( page.has_no_selector?('#results li.no-results'), 'No results is not shown' ) end Whereas an integration test is interested in a user’s interaction with an app, a unit test is narrowly focused on a small piece of code: When I call a function with a certain input, do I receive the expected output? Apps that are written in a traditional procedural style can be very difficult to unit test—and difficult to maintain, debug, and extend, too. But if we write our code with our future unit testing needs in mind, we will not only find that writing the tests becomes more straightforward than we might have expected, but also that we’ll simply write better code, too. To see what I’m talking about, let’s take a look at a simple search app: When a user enters a search term, the app sends an XHR to the server for the corresponding data. When the server responds with the data, formatted as JSON, the app takes that data and displays it on the page, using client-side templating. A user can click on a search result to indicate that he “likes” it; when this happens, the name of the person he liked is added to the “Liked” list on the right-hand side. A “traditional” JavaScript implementation of this app might look like this: var tmplCache = {}; function loadTemplate (name) { if (!tmplCache[name]) { tmplCache[name] = $.get('/templates/' + name); } return tmplCache[name]; } $(function () { var resultsList = $('#results'); var liked = $('#liked'); var pending = false; $('#searchForm').on('submit', function (e) { e.preventDefault(); if (pending) { return; } var form = $(this); var query = $.trim( form.find('input[name="q"]').val() ); if (!query) { return; } pending = true; $.ajax('/data/search.json', { data : { q: query }, dataType : 'json', success : function (data) { loadTemplate(&#
about 2 hours ago
Double the Price of your Next Web Design Project
Double the Price of your Next Web Design Project
about 2 hours ago
40+ Most Preferred Mobile Web Design For Inspiration
40+ Most Preferred Mobile Web Design For Inspiration
about 2 hours ago
10 Awesome Google Doodles For Inspiration
10 Awesome Google Doodles For Inspiration
about 3 hours ago
Xcode Vs Eclipse
Xcode Vs Eclipse
about 4 hours ago
Nowadays, almost every photographer use graphics software to completer the picture, like many painters used a “original version” in the past. Some artists use pure imagination to paint their artworks, other may prefer to crea...
Nowadays, almost every photographer use graphics software to completer the picture, like many painters used a “original version” in the past. Some artists use pure imagination to paint their artworks, other may prefer to create art by using a real life model as reference for the anatomy. What if these abstract models were real people?
about 4 hours ago
Top 7 Helpful Tools for Web Designers
Top 7 Helpful Tools for Web Designers
about 4 hours ago