So I’m dieting and exercising now…

For the last week, I’ve been dieting and exercising.  After seven days of hard work, I’ve managed to lose 5lbs, going from 194 lbs to 189lbs.

This isn’t my first time round the diet & exercise block. I’ve been in and out of diets and exercise routines for the last couple years, trying to get in shape and be healthy, but ultimately ending up back where I started. It wasn’t until watching a documentary called ‘Fed Up’ that I learned a lot about food balance.

Now, I’ve watched that Australian guy talk about juice and how vitamin rich juicing is, and I’ve watched that super-size me knockoff that talks about how beneficial fat actually is to the body, and I’ve watched documentary after documentary about how unhealthy meat is, the list goes on. But none of them – not one – talk about food balance.

Fed Up, though mostly about the food industry and childhood obesity, gave some really helpful insights to me about a balanced diet – specifically in regards to your sugar and your carbs. It gave the example of almonds, and how almonds are loaded with carbs, but the carbs our “balanced out” by the vast amount of fiber that is used to distribute sugar and carbs in your body properly – to be used as energy. Not having fiber, ultimately results in building fat.

So, upon learning all this, I took some initiative to do more research. Not just on sugar, but protein, fats, sodium, vitamins, etc. and have since developed my own diet & exercise plan.

Exercise

For exercise, I do cardio circuit training of some sort, twice a day. I wake up bright and early in the morning, hydrate myself, and do twenty minutes of high-impact cardio – sometimes incorporating weights. This seems like a drag to do, but once I’m done, and I cool off and get showered, I feel quite energetic throughout the rest of the day.

In the evening, I do another workout, usually no later than 7PM. This workout usually doesn’t incorporate weights, and lasts anywhere between 40-60 minutes. I work my abs, arms, and do full on cardio, all at the same time. Kicks, punches, situps, jacks, high-knees, jump-ropes, pushups, etc. All incorporated into a single workout.

In total, I burn anywhere between 800-1200 calories per day.

Diet

Before I go and say how many calories I eat – let me say, I eat a LOT more than I used to, more frequently, and I don’t let myself go hungry.

I’ve been taking advantage of the MyFitnessPal app, which lets you log not only your calories, but your fiber, protein, fat, etc. and sets a goal intake for everything.

For me, my goal intake is 1680 calories. Of those calories, 50 percent are to be carbs, 30 percent fat, and 20 percent protein. However, I don’t ever end up taking in that many calories.  Usually, I take in about 1200, if not less on some days. Seems crazy, right?

For me though, it’s not about the calories as much as what’s in them. I do my best to keep the percentages above in line throughout the day as much as possible. But on top of this, I have some rules for my carb and sodium intake.

First, I always try to stay under my sodium limit. Doing so allows me to keep that “water weight” off. If I end up exceeding it, I feel bloated the next weight, and ultimately gain weight, and avoid sodium as much as possible to have everything balanced out.

Next, is carbs vs fiber. I avoid added sugar as much as possible. Any and all sugar in any meal should come from a natural source, such as fruits and vegetables. Also, I try to apply the 10:1 rule; for every 10 grams of carbohydrates I take in, I should have at LEAST 1 gram of fiber.

As far as foods I choose to eat, I tend to eat mixed-green salads, veggie sandwiches, lean meats like chicken and turkey, fish (thank God I don’t have to give up sashimi!), fiber-rich protein bars/oats bars (such as FiberOne, or oatmeal) and lots of fruit. For those times when I need bread or pasta, I stick with whole-grain all the way, and have been substituting rice with quinoa. These are just the typical foods, there are also a lot of calcium rich foods and drinks I add on to recipes or meals, like cheese, almond milk, etc.

With the workout routine I have, I tend to get hungry every couple hours, so I usually go for some fruit; it doesn’t take a large portion of it to hold me over. 1/2 an apple, or one medium sized banana does the trick.

Doing this almost always allows me to meet my daily vitamin and calcium needs, but I have yet to exceed the 1650 calorie limit. And I never feel full.

So, what exactly is the diet? Stay balanced and natural. Whole grains, fruits, veggies, lean meats, and lots of fiber do the trick for me.

Well what about protein???

One thing that always gets brought up since doing this “natural” diet, and that is my protein intake. I’m constantly told that I need to be taking in a ton of protein, however, doing my own research, I’ve found that…I really don’t!

Now, I’m not saying I don’t need protein, but I AM saying I don’t need a ton of it. I try my best to meet that 20% mark mentioned before. Fact is, even while I’m working out as frequently as I am, I don’t need an excess of protein. I need just enough to allow my muscles to recover from the workout.

Many athletes and body builders require excess protein because they’re building muscle quickly; they need fast recovery times so they can push their muscles to the very limit in every work out. This is not my goal.

My goal is simply to push myself little by little to be more in shape, to eat right, and to be healthy. Doing this has kept my caloric intake low, but my energy level high.

Doing this, I’ve dropped all my water weight, losing five pounds in a week, while staying full and feeling more and more energetic, focused, and happy.

Things that keep me going

The number one thing that keeps me going is my weight and health. Seeing a difference in my appearance and seeing the number on the scale drop after only a week has been a huge motivator, but that’s not all there is to it.

I don’t feel limited. Yes, I am limiting myself when it comes to WHAT I can eat, but never WHEN. If I’m hungry at 9PM, I eat. Period. Midnight snacks? Why not! As long as it doesn’t throw off my nutritional balance goals, there’s no reason not to.

The food tastes better. Now, I owe this to my wife – she amazes me when it comes to home-cooked meals. She’s a master at taking recipes, making them healthier and lower in calories without compromising the taste and satisfaction of feeling full. Here vegetarian chili is delicious, and her turkey burgers beat any all-beef burger you can buy at any restaurant. Sorry, In-n-out, I’ve got you beat.

I get a cheat day. My wife and I have decided we should have a cheat day. Having a cheat day breaks up the routine and lets us enjoy some of our favorite foods that we’ve been sacrificing throughout the week. HOWEVER, it’s not so much a cheat day as it is a cheat meal. One meal can be as big as we want, with as many carbs as we want, with whatever drink we want, from wherever we want, and dessert is even welcome.  But that is it, and that’s enough.

I don’t punish myself for messing up. Yes, there have been days where I’ve had too many carbs, or too much fat, or too little fiber, etc. But it’s not something to beat myself up or get depressed over. I’m a bit of an emotional eater, so if I beat myself up over it, I’m going to end up eating a bag of oreos, or a carton of ice cream, or an entire box of mac n’ cheese. So instead of doing that, I make a mental note to do better the next day, and try extra hard to make that happen.

The positive changes so far

There are obviously a wide number of benefits to eating healthier and exercising.

For me, my weight dropping has been a confidence booster. I’m a little hard on myself when it comes to my appearance, so seeing the change in my body has kept me motivated and a bit more confident in myself in general.

I’m sleeping a lot better at night. Which ultimately makes it easier for me to work out in the morning. Win win!

I have a lot more energy. Combining the better night’s sleep with the built up endurance from exercising, I find myself not wanting to pass out when I get home from work.

I feel healthier. I’m headache and migraine prone. It seemed like every couple of days, I’d have a terrible head ache. However, since starting this diet and exercise plan, I haven’t had a single headache.

In conclusion…

If you take anything from this, and if I had any advice to give, have a balanced diet. You don’t need to workout as frequently as I am. The important thing here is to be healthy. Exercising every day is healthy, yes, but you don’t NEED to burn 1000 calories in cardio every day. Go for a walk, eat natural, vitamin, fiber, and protein rich foods, and avoid processed, sugary foods.

You’ll feel better, you’ll be healthier, and you’ll live longer. Take care of yourself.

In a few weeks..

Once a week, I will be taking pictures of myself to record my progress. These will remain private for now, however, I have a goal to meet in a few weeks. If I meet that goal, maybe, just maybe I’ll share the progress with an update.

How to make a living as a web developer

As someone who actually makes a living building websites, I thought I could share some valuable information on actually getting work, other than the typical “have a portfolio.” This isn’t exactly helpful to those who haven’t had a chance to build one.  And while a good portfolio will get you work, it’s not the “end all, be all”.  So in this article, I’m going to give you some advice and tips that just might help you land some work and make a living building the web.

Know your strengths

Face it, you probably don’t know EVERY language on the web like the back of your hand.  You may have your HTML and CSS down, but do you also know PHP, SQL, MySQL, Ruby, RoR, Perl, CGI, ASP, Angular.JS, DjangoDB, cURL, Python, Node.js, and the countless other languages and libraries out there on the web?  What about marketing?  Can you take data in Google Analytics and find ways to improve your website experience, or develop marketing strategies?

Don’t worry if you’re not a jack-of-all-trades.  What you can’t do isn’t nearly as important as what you can.  When you go in for a job interview, or when you’re looking for work, sell yourself on what you can do.

With that being said…

Never stop learning

While it’s important to capitalize on your strengths, it’s important to think of each language as a tool in a toolbox to build something.  When it comes to building stuff, you can do a lot more in more efficient ways when you have more tools under your belt.  So once you’re comfortable with a language, don’t just stop there, start learning another one.

Also, the web is constantly changing.  HTML5 and CSS3 are huge examples of that; CSS has brought smooth transitions and animations, and HTML5 has brought seamless geolocation, device & hardware detection, and more.  Stay up to date with what’s new and improved, and master those new features.

Self employed vs. In-house

Do you want to work for yourself, doing multiple projects for multiple companies and individuals, or do you want to work in house at a company?  Figure out what you want to do, or if you can even do it and start looking for work.

Develop your portfolio

Finding work without a hefty portfolio is a challenge, so be willing to work on the cheap (or even for free) until your portfolio is strong.  However, if you’re like me and you’re from a small town, that can be tough to do.  How do you market yourself to people in a town where things like web marketing and IT aren’t valuable or even necessary assets for a business?

Be willing to work for free to develop your portfolio.  Find friends, family members, etc., who can use your skills, and be willing to just do the work as a favor.  OR, you can easily find cheap work on websites like odesk.com

Know your worth as a contractor or employee

Don’t come out with the $75/hr rate right off the bat.  If you don’t have a portfolio or resume, why would anyone feel comfortable paying you market value?

Again, develop your portfolio and resume.  Keep track of your success stories and share them with future employers.  Once you can do that, you can start raising your rate close and closer to market value.

Join a staffing agency

Now, I recommend this strictly to build experience and develop a good resume and portfolio.  However, that’s my personal preference.  Some people feel more comfortable doing temp job after temp job because it’s like you get to do something new each time you start a new job.  Look up staffing agencies in and around your area and see if they have any jobs that match your skills/qualifications.  Join their agency even if they don’t; it won’t cost you anything, and if you match work that comes in, they’ll call you – no need to apply.

When I moved to the Silicon Valley to find work, I didn’t have the biggest, most impressive resume, so I found a staffing agency that would help me find work.  I’ve gotten several jobs through them, and I was able to use that experience to my advantage, and ended up landing something permanent.

Search for a permanent position at a company

Like becoming a freelancer in a small town, this is easier said than done.  I prefer this option, though.  Why?  Partly because I live in the Silicon Valley where tech startups are everywhere and pay a lot of money and the culture is usually really cool, but also because if I’m at a large or growing company, there’s always work to be done, there are great medical benefits and incentives, which is great when you have to support a family or a spouse.

Make and keep connetions

Whether you work at a company, as a freelancer, or as a contractor at a staffing agency, maintain good relationships with everyone you work with.  I’ve gotten a lot of freelance & contract work from word-of-mouth because I’ve stated connected with the people I’ve worked with.

Join LinkedIn

Despite what a lot of people say about LinkedIn, it’s a great place to stay connected with people you’ve worked with.  It’s also a great place to get public endorsements and positive feedback that you can share with potential clients or employers, as well as look for new work.  Most large companies and high-tech startups will post jobs here, and when they do, more often than not you can click a button and have your LinkedIn profile – including all your endorsements and work history – shared with them.

TL;DR?

Keep learning, keep growing, work hard, make connections.

Making WordPress functions.php Easy

WordPress’s functions.php could easily be considered the core of your theme. It adds unique, and often necessary functionality to your blog. You can enable features, or create new ones. In this article, I’m hoping to give some insight in not just making a custom functions.php file for your theme, but making it easy to manage.

How does WordPress the functions.php file work?

The short version – it extends what WordPress does by modifying existing actions – aka creating filters, or adding new ones, aka creating actions.  This is done using WordPress Hooks.

Rather than have ME explain it all to you, you should consider reading WordPress’s explanation of the functions.php file, so you can gain a more detailed understanding of how it works.

Don’t hand-code it all

While you COULD hand code everything - and I encourage you to learn – a good starting point might be to…well..cheat!  www.wpfunction.me is a handy website that lets you pick your own functions, and it gives you the code for it.  Post thumbnails enabled? No problem! Want to load a custom CSS file to theme your admin area? No sweat.

The nice thing about this tool is it can be a great way to familiarize with the logic behind the functions.php code.  Not sure about code snippet it generates? Google it or search the wordpress codex to learn about it.  Once you learn about it, tweak it, play with it until you get it exactly how you want.  Maybe make your own custom function!

Make it a plugin

The functions.php file is relative to your theme, so you want to be sure that whatever functionality you add to it specifically works to enhance your theme, but doesn’t take away from the core functionality of your blog should you ever change themes, because if you ever switch themes, your custom functions are gone unless you manually copy them over to your new theme.

One way to bypass this caveat is to make a plugin for every function that isn’t theme specific.

To do this, create a new folder for your plugin, and create a new php file inside it.  In this PHP file, insert the required plugin information headers need for WordPress to recognize the plugin, followed by your custom function, like so:

<?php
/**
 * Plugin Name: Name Of The Plugin
 * Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
 * Description: A brief description of the Plugin.
 * Version: The Plugin's Version Number, e.g.: 1.0
 * Author: Name Of The Plugin Author
 * Author URI: http://URI_Of_The_Plugin_Author
 * License: A "Slug" license name e.g. GPL2
 */

 //custom code here
 //you can find this example here:
 // http://codex.wordpress.org/Writing_a_Plugin
 //I strongly recommend reading WordPress's documentation
 //because it's relatively easy to follow, and it's
 //quite informative : )

 ?>

Now, take your new plugin folder and place it inside wordpress’s ‘plugins’ – or, ZIP the folder and upload it from the plugins section of the admin area.

If all works well, your function is now a plugin that you can enable, disable, and modify from within the admin area, no matter what theme you use!

CSS Selectors

To preface this article, I’d like to explain the basic logic behind CSS in how it relates to HTML.  So, CSS (aka Cascading Style Sheet) is the language that visually manipulates your text objects in your browser, i.e, your HTML.  To accomplish this, your CSS selects the object by some sort of identifier, then tells it what do, or how to look.

In this post I will show you just about all the CSS selectors there are – some that are pretty common, and others you may not have known existed.

HTML Tags

You can manipulate the way a specific type of HTML tag appears, or get really specific.

For example, if you want to style all your paragraph, or p tags, in your CSS, just type:

p {
	font-size: 14px;
	color: #000;
}

This will make all paragraph, or p tags have a font size of 14px, and be black. In general, you would want to call individual HTML tags to create a default style for that element.

Classes

Let’s say you want some of your paragraphs to have blue text. In the case where some HTML elements would need to be styled differently than default, you would use classes, both in your HTML and your CSS.

For example, your HTML might be:

<p>This is a normal paragraph.</p>
<p>This is also a normal paragraph.</p>
<p class="blue">This paragraph has blue text</p>
<p class="blue">This paragraph is also blue</p>
<div class="blue">
	<p>This paragraph will be blue, because its container has the class</p>
</div>

And your CSS:

.blue { color: blue; }

As you can see, even container classes can overwrite default classes. That’s the great thing about classes, you can use them multiple times on any element.

ID’s

Another basic selector is the ID attribute. In HTML, you can identify an element that is intended to be completely unique in some way – hence identifying the element by giving it a unique name. Remember, in HTML, ID names are intended to be unique – no ID should be the same in one page.

At any rate, you can style elements with unique IDs in CSS like so:

<div id="myDiv">
	<p>My Text</p>
</div>
#myDiv {
	width: 200px;
	height: 200px;
	padding: 20px;
}
#myDiv p {
	font-size: 18px;
}

See that? You can uniquely style HTML elements based on what element they sit in. In the example above, not only did I style the #myDiv element, but I styled the paragraph inside it. The same identifier rules apply for outer and inner elements, and you can be as specific as possible, for example:

<div id="myDiv">
	<p>This is my <span class="blue">blue</span> text!</p>
</div>
#myDiv p .blue {
	color: blue;
}

Now the text within the span tag that has the “blue” class inside the p tag inside the div named “myDiv” is now blue. Crazy specific!

BUT WAIT, THERE’S MORE!

States

Let’s talk links, or our a tags. Links have different states other than the default: :link, :active, :visited, :hover. I’ll go over all these states at some point, but for time’s sake, let’s tackle one of the most common, the :hover state. The :hover state changes the element’s default style when you hover over the item with your mouse cursor. In CSS, this would look like this:

a { 
	color: #000;
	text-decoration: none;
}
a:hover {
	color:#333;
	text-decoration: underline;
}

Quick note: another cool thing about :hover is it can be applied to other elements, p tags, div tags, etc.

There are other states for forms, such as :checked, :disabled, :enabled, :empty, :focus, :in-range, :out-of-range, :valid, and :invalid. For paragraphs, there is :lang(en) – of course ‘en’ would be replaced with whatever the ‘lang’ attribute is set to in your paragraph.

Attributes

The above CSS selectors are all pretty common; however, were you aware that you could select HTML elements based on their attributes?  Let’s use links as another example

<a href="/index.html">Home</a>
<a href="/pictures/">Pictures</a>
[href="/pictures/"] {
	color: #333;
}

This could also come in handy with forms, where you would use the same input element with a different type attribute.

When dealing with attribute selectors, there are different ways to select elements based on the contents of their attributes:

//The "target" attribute is equal to "_blank"
[target="_blank"] {
	color: #333
}

//the "alt" attribute contains the word "people"
[alt~="people"] {

}

//the "alt" attribute either equals "people", or begins with "people-" and another word
//for example alt="people" or alt="people-person"
[alt|="people"] {
 
}

//the alt attribute begins with or equals "people", either as a single word or on its own
//for example, alt="people" or alt="people person" or alt="peopleperson" etc.
[alt^="people"] {

}

//the alt attribute ends with the word "people" either as a single word or on its own
//for example alt="hard working people"
[alt$="people"] {

}

//the alt attribute contains the word people either as a single word or on its own
//for example alt="these are some people standing around"
[alt*="people"] {

}

Child Selectors

In CSS, you can select an element based on how many there are, or the order they are in within a containing element. These are known as child selectors. With these, the index, or the order you count them in, begins with “1” For this example let’s consider the html of this list:

<ul>
	<li>First</li>
	<li>Second</li>
	<li>Third</li>
	<li>Fourth</li>
	<li>Fifth</li>
</ul>
//the following are selected based on the order in which they are listed within the ul tag
//selects the first li element within the list
li:first-child {

}

//selects the last (Fifth) li element within the list
li:last-child {

}

//selects the Second li
li:nth-child(2) {

}

//selects all "even" li's, for example the second, fourth, and so on
li:nth-child(even) {

}

//selects all "odd" li's, for example first, third, fifth, and so on
li:nth-child(odd) {

}

Select by order or position

To continue this, using the same HTML list, you can also select elements based on the order they’re listed. With these methods, the index begins at “0”, not “1”. These are also global, meaning they will effect ALL specified html elements regardless of their container, unless specified. For example

//selects the First li
ul li:eq(0) {

}

//selects all li's that are NOT the Second li
ul li:not(:eq(1)) {

}

//selects all li's after, or "greater than" the First li
ul li:gt(0) {
}

//selects all li's before, or "less than" the Third li
ul li:lt(2) {

}

Sibling Selectors

Sibling selectors are ways to select elements based on how they are related to another element.

//selects the span element directly after an img element
img + span {
}

//selects all p elements within a div
div > p {

}

//selects all p elements in the same container as an element with the id of "hello"
#hello ~ p {

}

Select All

To select ALL elements within an html document

* {

}

Final Thoughts

It is important that you use valid HTML and define your doctype in your HTML document. It is also important – especially when using sibling and child selectors – to make sure that you can support YOUR audience’s browsers. A great way to do this is by visiting http://caniuse.com/ or use a JavaScript fallback.

Dealing with older browsers

The web is constantly evolving; the HTML language is expanding, CSS is getting more advanced, and we are finding more and more ways to make the web interesting.  However, for some reason, some people don’t upgrade their browsers, making it very difficult for us to share that creativity with others; so how do we deal with people who are running IE8, or even worse, IE6?

In this article, I’ll give you some tips and practices in no particular order that you can use to make life a little easier for you and your users.

#1:  Use a JavaScript Library like Modernizr

Probably the most common method of dealing with those pesky Windows XP users running Internet Explorer 8 or older (only joking XP users!  Windows XP is great, really it is.)

Modernizr is great, because it can be as light or as bulky as you need it to be.  On their website, you can choose which HTML and CSS elements you need to support, and build a modernizr script to help you.  It will tell the DOM to recognize HTML5 elements such as <section> or <nav>, and can add classes to the <body> tag so you can identify what is and is not supported in a particular browser, and use CSS and/or JavaScript to make any browser-specific changes necessary.

#2 Know your audience

Legacy browser support can be a massive pain in the butt; but as a web designer, your biggest concern should be to give your audience the best experience possible regardless of what browser they use.  So, spare yourself the headache and know your audience.  Use tools like Google Analytics to figure out how people are accessing your content, and develop your own standards & practices.

If you don’t know your audience yet, you can do 1 of 2 things.

  1. Take the Google approach and support only the latest three versions of the major browsers.  For example, if IE11 is the latest version of Internet Explorer, the oldest version of Internet Explorer you would support is IE9.
  2. Ask other people what their audiences look like.  If your website hasn’t been around long enough to gage who is using what, consider finding a company or asking a colleague in the industry what their numbers look like as a starting point, then, as your website gains traffic, use your own analytics to make your own decisions.

#3:  Test on older browsers

Never rely on just the latest version Google Chrome or Firefox to test your code.  Unfortunately, while browser “manufacturers” try to render code accurately and consistently, no browser is 100% equal.  People tend to rant and rave how IE is the absolute worst it comes to rendering code, but they aren’t the only ones you should worry about.

And sometimes, it’s not the browser alone, but the operating system.  Every operating system handles application text differently, not one is the same.  When QAing your work, you should test every version of every browser you intend to support on every operating system you intend to support.  How?

You could setup a virtual machine, but that can be tricky, expensive, and impact your computer’s performance.  I like to use BrowserStack.  BrowserStack let’s you choose between multiple versions of Windows, OSX, or choose different iOS or Android Devices, and multiple versions of the many browsers each operating system can run.  Need to test IE9 on Windows 7?  Easy!  Need to test Firefox 10.0 on OSX?  No Problem!  BrowserStack will give you remote access to a machine with the OS and browser of your choice through your browser, making it easy to test your website’s browser compatibility.

#4 Be Responsive

When building a web experience intended to reach people on multiple platforms, browsers and operating systems aren’t the only factor.  Consider the device your users are using, and the monitors they are viewing content through.  Different screen sizes, resolutions, etc., all play a huge role in your website’s usability.

Whenever possible, test your website in various resolutions.  A good start is to just shrink the size of your browser window.  Or, again, use BrowserStack.  Along with choosing the operating system and browser, you can set the desktop resolution all the way down to 800×600, or view your site through various devices, inheriting their viewport/resolution.

#5 Consider the fallbacks

As mentioned before, Modernizr can be used to determine what various CSS and HTML features a browser can support, and will add classes to the <body> tag for each unsupported feature.  Utilize this tool to create fallbacks.

For example, if you’re using CSS transitions for hover effects, use jQuery or JavaScript animation as a fallback.

Hopefully the above tips and practices above will help ease the strain of supporting older browsers.  How do YOU deal with older browsers?  What do you support, and what tricks do you use to support them?  I’d love to hear your ideas in the comment section below!

6778947365_2a33d3a9e5_o

PHP Include vs. Require – what to use and when to use it

In PHP, there’s a handy dandy little function called ‘include’ that basically allows you to run a php script from another file in your current script.  There is also a handy dandy little function called ‘require’ that basically does exactly the same thing.  Basically.  Likewise, there’s ‘require_once’ and ‘include_once’ which both due the same thing, but check the current document to see if its been included or required already, and won’t do it a second time.  So…which should you use, and when should you use it?

It all depends on the application.  With ‘include’, if an error occures in the included file, the remainder of your application can still function.  At most, you will see get a warning, but nothing more.  With ‘require’, if there is an error in the required file, the remainder of your application will not function, and your scripts will stop running.  Sounds scary, right?  Off the bat, it may seem like, from a usability standpoint, you should use ‘include’ or ‘include_once’ as a default – but this really isn’t the case.  Think of what you are implying.

If you use include over require, you are doing a few things:

  1. You are calling a script that may or may not need to run in your application at any given time
  2. You are potentially running code that doesn’t need to be running
  3. If your included file breaks, your application still runs – you’re trusting that there are no security or usability vulnerabilities without it.

As best practice, you really shouldn’t be including code that doesn’t need to exist.  At the very least, it can impact performance of your application.  ‘include’ should really only be used for ‘optional’ code, but…how often is code you write used only part of the time?  Very rarely.

Using require throws errors – which is a huge benefit in spite of how scary it may look.  Checking your server logs, or getting immediate feedback as to what broke in your code is crucial when developing.  If your required file patches a security loophole of some sort, it is obviously essential that your application stops running if the required file breaks.

So, best practices?

  1. The majority of the time, use require_once for scripts that are called only once – like a database connection, or defined functions.  You will probably use this the majority of the time.  You don’t often run into situations where you require a file more than one time in a script or application.
  2. Use require when the required file has scripts that run when the file called.
  3. Use include or include_once similarly, but only when they aren’t essential or carry sensitive or crucial data.  Which – how often do you include code that doesn’t necessarily matter?
  4. If your required file breaks your code, check your error info and your logs to find out why, and then fix it!  That’s the great thing about require!

PHP is a widely used language, but is full of security holes.  It is important to understand some of these basic practices as your develop your websites and/or applications in PHP to keep you and your users safe, and to make sure your code is running optimally.

Photo Credit

jquery_black

Should I Learn JavaScript or jQuery first?

The question for all JavaScript beginners these days seems to be “Should I learn JavaScript or jQuery first?”  It’s a good question, and everyone has their own opinion, neither is right or wrong for the person answering the question, but for the person asking…well it depends.

If you’re someone who has no JavaScript experience and hasn’t yet attempted trying to learn it, try leaning it first.  It has its own logic, and is a form of programming.  Learning JavaScript first will give you a good grasp of the logic and fundamentals/basics of programming – and you don’t need anything special to use it!  All you need is a text editor, a browser, and some basic HTML and CSS knowledge.

That being said…it can feel a little intimidating.  JavaScript on its own is a bit messy; it can be time consuming to not only learn, but accomplish simple tasks.  This is where jQuery comes in.  jQuery takes simple tasks and makes them easy to write and read.  For example, if you have a DIV with the ID of ‘container’, in javascript, to call that object, you would type the following:


document.getElementById('container')

With jQuery, you can just type:


$('container')

Easy, right?  The great thing about jQuery, is everything is readable.  While it might seem like cheating in some ways, it actually increases productivity without necessarily impacting performance.  If learning JavaScript from scratch is a bit intimidating, try jQuery.  It will teach you the fundamental logic of programming in JavaScript without having to learn every single detail of the language up front.  Eventually, as you start needing to complete more and more complex tasks, you’ll eventually start breaking away a bit from your dependance on jQuery.

One thing to note, if you decide to learn jQuery first, there might be a slight learning curve to jump over when learning basic JavaScript, because it’s easy to get comfortable with jQuery for basic tasks.  However, if you learn JavaScript from scratch first, jQuery probably seem like child’s play.

So, which is better to learn first? It’s up to you, really.  JavaScript gives you all the knowledge up front and will make jQuery easy, jQuery teaches you logic with readability, and might feel a bit less boring.