background preloader

Bestpractices

Facebook Twitter

Royfielding

Good Ruby Times. About eighteen months ago, maybe a bit longer, we began a process of deciding who we wanted to be as a company and what we thought we could achieve. At that time, and up until yesterday, we were ELC Technologies. We had managed to be quite successful as a Ruby and Rails developer with an Agile bent. We had a great deal of experience working in the Cloud, particularly on two pioneering services, AWS and Heroku. We were there as alpha testers and could feel like pioneers in the space. We just didn't want to be only that. It wasn't bad, but it wasn't ambitious enough for us. So, we started off with a mission: To create software that makes the world a better place to live, work, and play.

So, we needed to think bigger. It's a creative thing this software building thing, but it can be brutal, too. We can do the lean start-up, and scale it to the enterprise ready application developer. We are ready to create software that makes the world a better place to live, work, and play. The Complete Class. A remark: we enabled comment moderation because the blog was recently target of spam. You probably have not seen much of it because we were pretty quick in removing it manually. So if your comment does not show up please be patient. There are some basic concepts (often called “aspects”) that need to be implemented for many classes although not all classes need all (or even any) of them: initialization conversion to a printable string equivalence hash code calculation comparability cloning (clone and dup) freezing customized persistence (Marshal and Yaml) matching math and operator overloading Which of these is needed for a particular class depends of course completely on the circumstances.

We will look at these concepts individually in subsequent sections. Mutable fields redundant fields, i.e. fields which carry cached values that can be derived from other fields at least two fields for ordering priorities You will likely never implement all these aspects in a single class. Initialization. JavaScript Programming Patterns. JavaScript is meant to be used to add behaviour to a website, might it be for form validation or for more complex operations like drag & drop functionality or performing asynchronous requests to the webserver (aka Ajax).

During the past few years, JavaScript libraries became increasingly popular. One of the reasons is definitely that websites are getting more and more complex and reinventing the wheel each time is not acceptable if you are working on a tight schedule. But letting aside libraries and focusing on the “bare” syntax of JavaScript, it is very valuable to know what kind of options you have in terms of programming patterns when writing JavaScript. In this article I am trying to present some of the techniques out there that I have discovered. The patterns I would like to mention are the following: The way I decided to present and compare these different patterns is by solving the same given task with every pattern. The Old-School Way Please proceed to the working example. Coding: Reduce fields, delay calculations. A pattern in code which I’ve noticed quite frequently lately is that of executing calculations in the constructor of an object and then storing the result in a field on the object.

From the small amount of experience I have playing around with functional languages I have come across the idea of lazy evaluation of functions quite frequently and I think it’s something that we can apply in object oriented languages as well. When we store a value of a calculation in a field we are opening up the ability for that value to be changed before we use it. We can certainly reduce/remove the chance of that happening by making fields read only or final but as Dhanji points out in his InfoQ article, if we are storing reference objects there is still a chance they could be mutated before we use them. I don’t think the automated properties in C# 3.0 have really helped much and code like this is quite common: For example: S c h e m a t i c s : c o o k b o o k. Inapproprite Uses. Is fordescribing and displaying content JavaScript is forfunctionality Those are the appropriate uses for these technologies. Inappropriate use is when you cross those lines and create a mismatch.

Inappropriate database use You store the title of a blog post as the value: <h1>10 things to not bring with you skydiving</h1> It is inappropriate to store the HTML tag with the title. it's inflexible later on and has nothing to do with the content itself. Inappropriate HTML use People often say "HTML is for content", which is only partially true. Other inappropriate HTML use is stuff like: Chances are, that's there for purely visual reasons. Another example of inappropriate use, which needs no explanation: <p style="border: 1px solid red; padding: 10px;">Warning: you should never do this. Inappropriate CSS use It's harder to misuse CSS than it is other languages. It is possible to misuse it though, and one example is that CSS allows you to actually append content to HTML. Inappropriate JavaScript use. How Not to Write Code, II. Ok here's my view on the example in the last post. It's a little hard to assign blame or point to a particular failure as the root cause of the problem.

There are systemic problems beyond the obvious ones. I'll just point out a few problems. First and foremost is using local time. Time values should always be handled as UTC values. You can in theory handle everything as a local time if you retain the time zone, but this violates an abstraction. The underlying problem is conflating the presentation with the representation. But the programmer who coded this up in the first place can't be blamed too much because there are problems with the software involved in presentation and persistence. The database was a major problem. Ideally, you'd like a rich object model that worked from end-to-end. The last issue is the insane workaround. There are dozens of ways to fix this bug, and nearly all of them are better.

Different Ways To Format CSS. This post will focus on the different ways to format CSS, which differs from the different ways to organize CSS. Definitely related concepts, but I think organization has more to do with how things are grouped and ordered while formatting has to do with spacing and indenting. Formatting has nothing whatsoever to do with how the CSS functions. These are merely aesthetic choices by the coder. But that's not to say formatting isn't important. That would be like saying the choice of canvas isn't important to a painter. It affects how it feels to write CSS, how easy it is to read, how easy it is to navigate, and how easy it is to revisit and reacquaint yourself with previously written CSS.

The reason there are so many choices with CSS formatting is that there are no hard syntax rules when it comes to spacing and line-breaks. Is the same as: Multi-line Format I'd wager to say this is the most common. Multi-line Format with Indenting Single-line Format Single-line Format with Tabbing Variations Combo. Where do you require? I was recently looking over a codebase and noticed that several different files contained require statements. I'm not talking about the require statement that each test file has, I'm taking about seeing require 'ostruct', require 'enumerator' or require 'soap4r' in numerous class definitions. For the last few projects I've been following the convention of putting all the require statements in environment.rb. There are more efficient strategies, but I find this to be the most maintainable of the solutions I've tried. While following the above strategy I haven't run into any issues with two libraries defining behavior on differing classes that are named the same, but I have heard concerns from team members on the time it takes to require each library.

I think that's a valid concern and I was planning on addressing it by writing a method that takes an array of strings and requires them one at a time. How to Write an Equality Method in Java. How to Write an Equality Method in Javaby Martin Odersky, Lex Spoon, and Bill VennersJune 1, 2009 Summary This article describes a technique for overriding the equals method that preserves the contract of equals even when subclassses of concrete classes add new fields. In Item 8 of Effective Java1, Josh Bloch describes the difficulty of preserving the equals contract when subclassing as a “fundamental problem of equivalence relations in object-oriented languages.” Bloch writes: There is no way to extend an instantiable class and add a value component while preserving the equals contract, unless you are willing to forgo the benefits of object-oriented abstraction.

Chapter 28 of Programming in Scala shows an approach that allows subclasses to extend an instantiable class, add a value component, and nevertheless preserve the equals contract. Although in the technique is described in the book in the context of defining Scala classes, it is also applicable to classes defined in Java. 1. 2. 3. Best Practices for Ezine Newsletter Publishing and List Manageme. This document provides my set of best practices for ezine newsletter publishing and list management.

I have searched for ezine best practices, newsletter best practices, list management best practices and several other best practices keywords. And, I have used these other resources for both general inspiration and specific concepts. But ultimately, the responsibility for this list is my own. I send out an ezine (newsletter) called . And I manage that newsletter on my own computer using Gammadyne Mailer . Recently, I also created a small "private" ezine. As I began my search, I remembered encountering an organization known as MAPS (Mail Abuse Prevention System) and their document called " Basic Mailing List Management Principles for Preventing Abuse ".

Continued searching also led me to BestPrac.org and their ideas, as well as other resources I have listed below. I've used these resources, together with my information, observations and insights, to construct this list of Best Practices. 11 Link Usability Tips. How I write JavaScript Widgets. Improving the structure of the code I write is an ongoing concern. Over the last while, I feel I've settled in to how I write HTML/CSS/JavaScript widgets and find the pattern repeating itself over and over again. The code example below is a simple little logger widget.

It appends messages to a list and has a clear link to delete all the recorded messages. I use the module pattern around each widget constructor function. I write the module pattern as the following. Having the explicit global variable makes it clear the MY_makeLogger function is global. When real-world code grows larger than a small example, it is some welcome clarity. (function() { var global = this; // ... })(); Several library functions are prefixed with LIB_ to avoid collisions.

The library functions are all common components of most libraries. At the top of the module, before the constructor function, are helper functions which do not need to capture in their closures' the widget's state variables. Hypertext-driven URLs. Roy T. Fielding, author of the REST thesis wrote an article recently: REST APIs must be hypertext-driven. I liked this article, it fit with an intuition I’ve had.

Then he wrote an article explaining that he wouldn’t really explain the other articles because, I guess, he wanted a conversation with the specialists, and it seems like a kind of invitation to reinterpret his writing. So since others are doing it I figured I’d do it too. I’d summarize his argument thus: Focus on media types, i.e., resource formats, i.e., document formats. The protocol will flow from these if they are well specified.URL structures are not a media type. An example of a protocol based on a URL structure would be something like: Do GET /articles/ to get a JSON list of all the article ids, with a response like [1, 2, 3]Do a GET /articles/{id} to get the representation of a specific article.

JSON is a reasonable structure for a media type. You start with a container, in our example /articles/. <entry>... Elements of Ruby Style. Next week marks the publication of the 50th Anniversary edition of the Strunk & White’s The Elements of Style, a critically important work for anybody who puts words together on a regular basis. In that spirit, here are some thoughts on good Ruby & Rails style — I’m mostly focusing on Ruby-specific guidelines here. This is somewhat closer to a brain dump than a fully-baked style guide, so it’s something I intend to come back to, especially after hearing everybody tell me exactly where I’m wrong, wrong, wrong. UPDATE: There were some comments about the formatting being messed up.

Apparently whatever tool we’re using for code coloring doesn’t work well with Safari. In Firefox, the formatting is as intended. The goals of well-styled code are correctness and simplicity, in that order. I don’t want to pretend that it’s not important for code to be correct. Ruby code should be indented two spaces. This should be uncontroversial, right? <% if something %> two spaces <% end %> Not this: But this:

Two Things Design Experts Do That Novices Don’t. In my research on concept design processes, I’ve come across two ideas that jumped out as vital behavior that differentiates expert designers from novices. The first comes from Nigel Cross of Open University, UK, who seems to have studied designers and their processes more than anyone I’ve come across. In his Expertise in Design (pdf) he says (emphasis mine)… Novice behaviour is usually associated with a ‘depth-first’ approach to problem solving, i.e. sequentially identifying and exploring sub-solutions in depth, whereas the strategies of experts are usually regarded as being predominantly top-down and breadth-first approaches.

While the protocol studies he cites contradict this, when it comes to digital design I find this explains why I see so little concept design these days. The other big idea comes from How Designers Work, Henrik Gedenryd’s Ph.D dissertation. In short, experts are pragmatists, they re-set or re-frame the problem to make it solvable. 10 Essential Principles of the Javascript Masters. 7 Essential Guidelines For Functional Design. Advertisement Look at what you’ve made. Beautiful, isn’t it? But does it work? For whom does it work? At the heart of every piece of practical design, whether it be a website, product package, office building, manufacturing system, piece of furniture, software interface, book cover, tool, or anything else, there is a function, a task the item is expected to perform.

These are the elements of functional design, the process of responding to the needs or desires of the people who will use an item in a way that allows their needs or desires to be met. In order to create a product that works, there are seven questions you should keep in mind about the product you’re designing, who will be using it, and how they’ll be using it. 1. Consider the screwdriver.

Ultimately everything in a screwdriver’s design is aimed towards the accomplishment of that single goal: driving screws. Now, consider a website like Amazon.com2. For the folks at Amazon, the website has one purpose: to sell stuff. 2. 3. 4. Python best practices. How to get Cross Browser Compatibility Every Time. Complete Contents. Java Practices -&gt; Home.