Why coding standards are useful and important

. Why coding standards are useful and important

1. I'm Chris Shattuck and the is Coding Standards. In this video, we're going to cover what coding standards are and how they make life better. Just by putting your code in a module and using the hook system in Drupal API's, your code is going to follow a number of conventions that other modules follow. And so even if you're not aware of coding standards, it should be fairly straight forward to pick through your code and figure out what is going on.

2. What coding standards do is add an extra layer of readability to the code and basically polish. And this polish has two functions. The first is very functional and it has to do mostly with what happens when another developer is looking at your code.

3. We all come from different backgrounds of different programming languages and we've learned how to code from a variety of different sources. So we come to the table with different ideas about what makes code easier to read. Maybe we like curly brackets.

4. Maybe we like indentation better. Maybe we want to leave out as much as we possibly can and condense or code into the smallest possible format. And this is fine as long as we're working by ourselves but as soon as another developer comes into the picture, they'll find the same things that we find particularly nice about our syntax, very annoying or irritating.

5. And while it's not impossible to get around or impossible to understand code that's in that structure, there's going to be a little bit of resistance to working with it and there'll be the tendency to rewrite that code to follow their particular syntax. Their structure that they like to use. By all developers agreeing on a particular syntax that covers all the nuances of coding, it means that the time that would be spent rewriting code to match the syntax we like and having that undone by the next developer is saved and can be used toward the development process itself.

6. And it means that we don't get frustrated then by another developers style. Instead we can be frustrated with the standards and if there's actually a problem there, there's an outlet to discuss that and figure out if there might be a better way than the current coding stands dictate. The second thing you get from the polish of using coding standards, is a little less concrete.

7. And it has to do with what happens when you share your code publicly. More seasoned Drupal developers, when they being to review code in a module, they'll look first at whether the coder is using coding standards. And if they're not, then the'll extrapolate from that and assume that the coder probably hasn't familiarized themselves with the best way to interact with Drupal's API's, and how to write secure code as well.

8. And it will become a sticking point, so following coding standard is a lot like getting past the bouncer into an elite club. Basically it improves the chances of the functionality and ideas behind your code being taken more seriously. We're covering coding standards fairly early on in this video series, because in order to get comfortable with them, you need practice.

9. And the video in this series will give you ample opportunities to get that practice in. Most likely by the end of this series, it will be second nature and you won't even have to think about it. The best place to learn about Drupal coding standards is "drupal dot org slash coding dash standards".

10. This page contains details about syntax orientated coding standards and if you scroll down you'll see that there's a good bit of meat to this page but it's not too terribly long. So even though we're going to go through the details of this page in a more summarized format, it's a good idea to read through this as soon as you have time. Also, on the right hand column you'll see there are a number of sub pages to this page that include more specific information about commenting, SQL coding and other more specific subjects.

11. What I've done for this video is created a very simple module to demonstrate most of the coding standard concepts in a simplified fashion. You can use this module both as a reference and as a sandbox to play with the code that's in it and see if you can get it standard compliant. So go ahead and open your "buildamodule" resource folder and copy the standards module and we're going to paste this into our sites, all, module, custom folder.

12. Ok. Let's go ahead and refresh our modules page on our site at "admin slash modules" and if we scroll down near the bottom we should see a "BUILD A MODULE" section and in here we should see a standards module. Now we don't actually need to install the module.

13. We can do pretty much all we need to do for this video by just taking a look at the source code. So let's go ahead and open up our dot module file. The structure of this module is very simple.

14. We have two functions. One is an implementation of "hook_menu' called "standards_menu" and it's adding a page to allow us to demonstrate the coding standards inside of a page so if you wanted to mess with the code and see how it changes the output, you can do that. And then we have the function that actually generates a page called "standards_page".

15. This file contains a number of comments. At the top here you have a link to the coding standards page just in case you need a reference there. And then inside the standards page are a number of comments followed by examples of the coding standards so we're going to go through this example by example.
Drupal 7 Development Core Concepts

In our most popular collection, we build a strong foundation for developing in Drupal, covering the most commonly used APIs, building practical and interesting modules, and covering a tremendous amount of ground. Just a few of the topics we cover:

  • How to build and manipulate forms with the Form API
  • How to write jQuery to build a rich interface
  • How to programmatically manipulate content and user data
Video Library
21m 46sIntroduction
21m1. Welcome to BuildAModule
10h 36mBuild Your First Drupal 7 Web Site
36m1. Introduction to Our Project and Reviewing Mockups
35m2. How to Create and Edit Content
38m3. How to Work With Menus, Modules and Webform
41m4. How to Work With Content Types and Fields
37m5. How to Work With Pathauto and Introduction to Views
32m6. How to Add Fields to a View and Work With the Date Module
36m7. How to Fix Broken Views and Work With Taxonomy
35m8. How to use Term and Node Reference Fields
31m9. How to Work With Blocks and Permissions
31m10. Overview of Permissions and Text Formats
34m11. Configuring Text Formats and Setting Up a Wysiwyg
33m12. Working With Custom Blocks and Image Styles
34m13. How to Work With CSS
34m14. Troubleshooting Module Installation and Configuration
33m15. Updating Modules and Manipulating CSS
32m16. More CSS Updates and Troubleshooting Text Formats
31m17. How to Evaluate Modules and Install IMCE
44m18. How to configure IMCE and Wrap Up Our Project
6h 18mAdvanced Site Building in Drupal 7
23m1. Welcome to Advanced Site Building
30m2. How to Set Up Administration Tools to Speed Up Productivity
36m3. How to Configure Content Type Settings and Splitting Fields Between Types
41m4. How to Use Display Suite for Grouping Fields and Positioning Content
14m5. How to Use the Context Module for Positioning Content
42m6. How to Use Panels for Positioning Content
48m7. How to Import Content With Feeds
48m8. Advanced Views
30m9. Where Display Modules Overlap and URL Strategy
28m10. How to Work With User Fields and Import Users
34m11. Formatting a Blog Entry Page
12h 48mPHP Programming Basics
25m1. Series Introduction and Your First PHP Script
45m2. Working With Strings and Variables in PHP
31m3. How to Work With Arrays in PHP
40m4. Logic, Control Structures and Looping
1h5. Creating Custom Functions and Working With External Data
22m6. Troubleshooting errors and using operators
1h7. Working With Forms in PHP
1h8. Working With Sessions in PHP
1h9. Working With the (MySQL) Database
1h10. Working with CRUD functionality and our database
2h11. How to Build Your Own Content Management System and Understand Drupal Better
1h12. Generalizing Functionality and Object Oriented Programming Primer
12h 23mDrupal 7 Development Core Concepts
22m1. Welcome to Module Building
35m2. How to Build Module Scaffolding
1h3. How Hooks Work and How to Use Them
26m4. Overview of Coding Standards
51m5. Development Tips and Tricks
1h6. How to Build and Manipulate Forms with the Form API
1h7. How to Add and Manipulate Pages With the Menu System
52m8. How to Add to and Manipulate the Theme Layer
1h9. How to Work With the Database
54m10. How to Work With Users
1h11. How to Work With Nodes
2h12. How to Work With JavaScript and jQuery
9h 25mChange Management and Version Control
49m1. Installing Git and Working on the Command Line
58m2. Staging, Committing and Undoing in Git
34m3. Branching, Merging and Tagging in Git
1h4. Working With Remote Git Repositories
38m5. Deploying Releases, Features, and Fixes With Git
24m6. How to Version Control the Database
1h7. How To Version Control Site Configuration With Features
25m8. How To Manage Non-Exportable Configuration Changes
57m9. How to Override Shared Features and Modify Text
33m10. How to Upgrade Drupal and Patch Contributed Modules
37m11. How to Install Drupal, Manage Features and Perform Common Tasks Using Drush
31m12. How to Configure Drush and use Drush Make
37m13. How to Extend Drush and Other Useful Drush Tools
8h 1mDrupal Theming Essentials
1h1. Important Drupal Theming Concepts
1h2. How to Build and Modify a Drupal Theme or Sub-Theme
1h3. How to Build and Modify a Drupal Theme or Sub-Theme, Part 2
54m4. Theme CSS File Structure and Extended Drupal Theme Building
1h5. Template Files, Theme Function Overrides and Preprocessing Functions
1h6. How to Work With Drupal Theme Settings
8h 55mDrupal 6 Development and Tools
3h1. Essential Concepts
27m2. Working with jQuery and Javascript
1h3. Securing a Module
58m4. Testing and Debugging a Module
1h5. PHP and MySQL Basics
1h6. Using Komodo Edit as an IDE
2h 17mWorking with Files and the File API
39m1. How to Work With Files and the File API
1h2. How to Work With Files and the File API, Part 2
22m 53sAppendix
22m1. Mentored Training Resources
Double-tap to return to library

Loading...