Code sample confusion I work with Drupal almost everyday. I am constantly scouring the web for help on my current Drupal project. I come across many code examples and samples. I'm wondering how the code relates to Drupal from a module standpoint. Does anyone create a "general" module to add and interact with their Drupal site? Like a gateway to actually code things in their Drupal site instead of using the countless forms and views that encompasses normal Drupal development. Or am I getting it all wrong and the code examples are for specific modules that people are making?

A couple of code examples I come across and think to myself - "This is very general. I would like to use this but do I need to make an entirely new module?" are: 

&lt;?php
global $user;
print_r($user);
?&gt;


or 

function HOOK_views_api() {
  return array(
    'api' =&gt; 3.0,
    'path' =&gt; drupal_get_path('module', 'HOOK')
  );
}

function HOOK_views_default_views() {

  // Paste code form views export.

  $views[$view-&gt;name] = $view;
  return $views;
}


It seems like a lot of extra nonsense to create an entirely new module just to add some simple programming functionality to the site and to take advantage of the Drupal API, and to do this every time I want to program something instead of work with the UI.

Sorry for such a weird and general question but I'm just trying to wrap my head around it. Let me know if I'm completely wrong too.

Thanks!
You are headed into right direction: almost all websites I work on, have one main module that contains general customizations and provides the base for additional custom modules.
I find that this is absolutely necessary if you want to keep the sanity in the long run, especially if the project can potentially grow.

Small fixes are often faster and easier to maintain this way, rather than just adding more modules and making the configuration more complex.

I created a boilerplate module that we use as "Main" module for almost every Drupal installation.
You can see it here.

Most of the generic implementations / integrations (views, rules, webform, drush, helper functions, etc.) are there already, and it's much easier to just remove what you don't need.

On a related note, the same can be said for new Drupal installations. After creating a lot of Drupal websites for real projects and testing, you will realize that there are certain sets of modules and settings you want to have as a starting point. This is solved the best through installation profiles.

Here is a default installation profile that we use in almost every website, as well as for testing.

Hope this helps.