Probably Wrong | Avoid Else, Return Early tldr; Return as soon as you know your method cannot do any more meaningful workReduce indentation by using if/return instead of a top-level if/elseTry keep the “meat” of your method at the lowest indentation level.Error handling is noise. Programmers are often taught to have a ‘single exit point’ in their methods, i.e. only return from a single location. function () { var result; if () { result = x } else { if () { result = y } else { result = z } } return result // this return is single and lonely } This is a poor guideline in my opinion: “assign a result” doesn’t explain the intent: “this is the final value, processing stops here”Leaves question open “is the result object finished? Example if/else refactoring Consider this typical node callback code: function(err, results) { if (! There’s a few problems here. Let’s try keep the “meat” of the code at the bottom of the method, and keep any special cases together at the top: function(err, results) { if (err) return void handleError(err) // ... }
Codecademy Labs OverAPI.com | Collecting all the cheat sheets Named Constructors in PHP Don't limit yourself by PHP's single constructor. Use static factory methods. Published on 12 June 2014 by @mathiasverraes PHP allows only a single constructor per class. <? The only correct answer is “it depends”. This is terribly ugly. <? Or if we want to support numeric strings as well as integers? <? (Note: in production code, I would make my Time class a lot more idiot-proof.) Refactor to named constructors Let’s add some public static methods to instantiate Time. Every method now satisfies the Single Responsibility Principle. Well, something is bothering me: __construct($hours, $minutes) kinda sucks: it exposes the internals of the Time value object, and we can’t change the interface because it is public. This is ugly: we go through all the trouble of splitting up the string, only to rebuild it in the constructor. Do we even need a constructor now that we have named constructors? <? <? Ubiquitous Language <? Notice anything? fromString => fromTime fromValues => fromHoursAndMinutes <?
30 free programming eBooks - citizen428.blog() Since this post got quite popular I decided to incorporate some of the excellent suggestions posted in the comments, so this list now has more than 50 books in it. BTW: I’m not very strict on the definition of “ebook”, some of them are really just HTML versions of books. [UPDATED: 2012-01-18] Learning a new programming language always is fun and there are many great books legally available for free online. Here’s a selection of 30 of them: Lisp/Scheme:Common Lisp: A Gentle Introduction to Symbolic ComputationHow to Design ProgramsInterpreting Lisp (PDF, suggested by Gary Knott)Let Over LambdaOn LispPractical Common LispProgramming in Emacs LispProgramming Languages. Ruby:The Bastards Book of Ruby (suggested by Dan Nguyen)Clever Algorithms (suggested by Tales Arvelos)Data Structures and Algorithms with Object-Oriented Design Patterns in RubyLearn Ruby the Hard WayLearn to ProgramMacRuby: The Definitive GuideMr. Erlang:Concurrent Programming in ErlangLearn You Some Erlang for Great Good
Aptitude Questions and Answers - IndiaBIX Prettier for PHP 0.1: First alpha release □ · Prettier After more than 200 merged pull requests since mid December 2017, we're happy to announce the first alpha release of Prettier for PHP. In this blog post, we'd like to give a short overview of how the plugin works, its philosophy, and what to expect in the future. How does it work? Adding support for a new language to Prettier requires two things: A parser, which turns your source code into an abstract syntax tree (AST). While we could benefit from existing work on the parsing side, the printer had to be developed from scratch to support all of PHP's various AST node types. If you'd like to read more about the plugin API, see the docs. Philosophy When building a code formatter, it can be tempting to add many options to account for all the different code styles there are. From the experience gained with Prettier for JavaScript, we believe that offering as few configuration options as possible is one of Prettier's biggest strengths. What's next Are you excited about Prettier for PHP?
code snippet: Add a New Table to an Access Database Category: Database Type: Snippets Difficulty: Beginning Author: Intelligent Solutions Inc. Version Compatibility: Instructions: Copy the declarations and code below and paste directly into your VB project. Declarations: ' (None) Code: i heart intelligence Top 40 Useful Sites To Learn New Skills You just have to know where to look. Sure, you can use Google, Yahoo, or Bing to search for sites where you can learn new skills , but I figured I’d save you some time.Here are the top 40 sites I have personally used over the last few years when I want to learn something new. Here are the top 40 sites I have personally used over the last few years when I want to learn something new. Hack a Day – Hack a Day serves up fresh hacks (short tutorials) every day from around the web and one in-depth ‘How-To hack’ guide each week. eHow – eHow is an online community dedicated to providing visitors the ability to research, share, and discuss solutions and tips for completing day-to-day tasks and projects. Wired How-To Wiki – Collaborate with Wired editors and help them build their extensive library of projects, hacks, tricks and tips. MAKE Magazine – Brings the do-it-yourself (DIY) mindset to all of the technology in your life. 5min Life Videopedia – Lot’s of great tutorials and DIY videos.
A list of cool Chrome DevTools Tips and Tricks The Chrome DevTools provide an amazing set of tools to help you develop on the Web platform. Here are a few tips you might not know yet Check out the overview of Chrome DevTools if you're new to them Drag and Drop in the Elements panel In the Elements panel you can drag and drop any HTML element and change its position across the page Reference the currently selected element in the Console Select a node in the Elements panel, and type $0 in the console to reference it. Tip: if you're using jQuery, you can enter $($0) to access the jQuery API on this element. Use the value of the last operation in the Console Use $_ to reference the return value of the previous operation executed in the Console Add CSS and edit the element state In the Elements panel there are 2 super useful buttons. The first lets you add a new CSS property, with any selector you want but pre-filling the currently selected element: Find where a CSS property is defined Save to file the modified CSS Screenshot a single element