Programming Language Geek

November 23, 2009

Javascript: AJAX Tips

Filed under: Javascript

AJAX offers extra dynamic web pages to the point that it could be possible to update or dynamically change a certain page without actually reloading it. In order to maximize its capacity, you should be able to consider some important points. First, since AJAX is Javascript, it is more likely very prone to security flaws due to the fact that it is executed in the client side. Therefore, its security is not assured. Second, though the "X" in AJAX stands for XML, it does not all the time mean that you have to use XML to pass data from the client to the server and vice versa. Finally, since AJAX offers the "no-refresh" dynamic web page update, it also means that if the user accidentally presses the browser’s Refresh or Back button, then there is a possibility that the user’s current page may be lost. Anyways, here are my AJAX tips:

  1. Use JSON instead of XML - JSON is more lightweight than XML, therefore it is transferred faster and is as efficient as XML. Though if used with PHP’s "jsondecode()" to translate JSON into objects or arrays, it may not support characters other than UTF-8. In order to solve this problem, it is possible to use a Javascript base64encode() for each value in the JSON string, then later on use PHP’s base64decode() to decode the characters.
  2. Include a dynamic sha1() encoded session parameter for every AJAX request - Always use $SESSION[] to store the dynamic session and compare their values every AJAX request. This is to ensure that the request is authentic. If and when it is not authentic, then you may have the advantage of canceling the request since it is already considered invalid.
  3. Use sessions for every dynamic web page update - Everytime the page is being updated, always use sessions to determine how far the user has gone through. So that if the user accidentally presses the Refresh or Back button, he can still continue to work on the web page without starting from the very beginning.
AJAX is a powerful feature of Javascript. Though most developers claim that it is open to several security issues, it won’t unless it is not taken with full responsibility. I would personally recommend AJAX, and don’t forget to consider those tips mentioned above.

November 11, 2009

Top 3 most common PHP errors

In a DHTML platform such as PHP, the most common programming errors which are truly difficult to even notice are those which are related to variable declaration and certain operations. Here’s a list of them which I personally experience the most:

  1. Conflicting variable names - This one’s a pain in the neck. Since PHP’s way of declaring, assigning, and calling variables are similar, there’s no way it can prompt the programmer that there’s already a variable in conflict with a previous declaration. For example, variable "$var" is declared and initialized as "$var = null;" Later, even if you have in mind declaring another variable and you forgot that you already have "$var" in the earlier part, a statement such as "$var = true;" won’t be considered a declaration, but rather, an assignment. Which means, it’s value is changed from "null" to "true".
  2. Appending an operation to a string - Producing a string wherein a part of it is a result of an operation such as this: "$str = ‘Hello ‘ . 1 + 25 . ‘ World’;" doesn’t work, but this will: "$str = ‘Hello ‘ . (1 + 25) . ‘ World’;" If you are to append or include a mathematical operation in a string, it should always be enclosed in parenthesis. Well, anyway, in programming, the use of parenthesis in any statement is always a recommended practice.
  3. Missing the $ sign - Upon calling a variable for a certain operation, PHP does not generally produce an error for variable typos without the "$", and it’s pretty difficult to detect, because it would seem it doesn’t have any problem, but actually, it’s a very big problem. I believe, once an undeclared variable without the "$" is being called, it is considered as a literal string or a number.
These 3 are just some of the most time-consuming problems I usually meet. So, if ever you find out that you can’t have your script get to work though it seems to be free from errors, then don’t forget to consider these neat lessons.

July 16, 2009

Mass Post plugin for MWM Panel

Filed under: Uncategorized

A common subject and a few keystrokes for the content plus a single push of the Publish button, then here comes this post to all 3 of my blogs at the same time. This is the Mass Post feature of MWM Panel. I’m currently testing it to 3 blogs. Later, I shall try it on to a hundred. But anyway, this petty project’s going to be huge soon. Check out these blogs for the simultaneous posts:

  1. http://ronaldborla.blogsome.com
  2. http://ronaldborla.info
  3. http://plgeek.blogsome.com

I hope that sounds cool to you too. Ciao!

June 10, 2008

if.. else if.. statement

Filed under: C / C++

Suppose you are trying to set conditions that if ever your condition will be met, then it does the first step, Plan A. If the condition will not be met, then it will execute Plan B. These are just some of the functionalities of the "if.. else if.. statement".

The syntax:

if (condition){
some statements…
}

Note that the statements to be executed should be enclosed within two brackets (open bracket { and close bracket }). The characters above in bold should be strictly followed since this is the actual syntax of the statement. The condition is boolean. If it returns no value, then it’s considered false, while otherwise, it’s true.

Some statements represents the statements to be executed whenever the condition is true. If not, then the statements will be skipped. To handle conditions much more effectively using if statements, you can add the else or else if statement.

if (condition){
some statements…
}
else if (another condition){
some statements…
}
else{
some statements…
}

Now how does the compiler handle these statements? First, it checks the first condition it encounters. If the condition is true, then it will execute the statement enclosed within it. If not, then it searches for an else if statement until it meets the condition which returns true. If not still, then it will look for the else statement. When it reaches the else statement, the codes included within it will right away be executed. Notice that in the else statement, there is no condition required.

Later on, we’ll be discussing some variations of the if.. else if.. statement. Just take note of the concepts since you might be applying this in the future. 

May 26, 2008

C / C++ Variables

Filed under: C / C++

You should be able to remember about variables in Mathematics. Well, they just have the same concept as variables in programming. They act as a temporary storage for constant values like characters and numerics. These variables are declared, and as soon as you do that for your programs, a memory space will automatically be allocated and reserved for an expected value. While they’ll be destroyed whether manually or automatically, depending on the designation of the programming language, whenever they will no longer be of use. Note that these variables consume the random access memory to temporarily allow lots of application functionalities. So, as a programmer, you are solely responsible of how much or how less variables you need to create.

In a C / C++ Programming Language, the format to declare a variable is as follows:

variableType variableName;

variableType is the type of the variable to declare. Here is a list of common C / C++ variable or data types :

Data Type
Origin
Bits Allocated
Description
int
Integer
16 Bits
Stores numbers approximately from -2147483648 to +2147483648.
char
Character
8 Bits
Stores character with ASCII values from 0 to 255.
float
Floating
32 Bits
Stores up to 4 Bytes of floating numbers.
double
Double Floating
64 Bits
Stores up to double the size of float.
bool
Boolean
8 Bits
Stores values whether True or False.

variableName is the name you will be defining for the variable. Which means, you decide what you call it. One good technique upon declaring variable names is through relating it with its purpose. In this way, you won’t easily forget the name of the variable. Also, as a rule for naming variables, you have to consider that: it should not start with a number; it should not contain any spaces and other special symbols such as #, $, %, * and more; it must not conflict with default C / C++ terms such as "if", "switch", "enum", and more.

Since variables are able to store values, depending on its nature, you can either assign a constant value for it or a value from another variable of the same data type. So, if the variable type is int, then you may only assign integer values for it.

To assign a constant value to a variable:

int num;
num = 15;

To assign a value from another variable:

int numVal;
numVal = num;

Remember that variables are very important in programming. It is always fully recommended to use variables most of the time. These help lessen confusion, prevent mistracking of values, and strengthen the construction of algorithms, which in the end improve the quality of programming.

Note: In the above C / C++ declarations, they all end in a character symbol ";". This tells the compiler that a statement has been ended or closed. So, if these won’t appear with each statement, it would most likely produce a compilation error. The compiler will always search for this symbol.

May 19, 2008

Conditions : True or False

Filed under: General Programming

Probably all programming languages depend on conditions. A condition is the most basic feature programming possesses. It allows programs to behave in a dynamic manner. These are like pathways being split up everytime decisions have to be made. Basically, conditions return only values either True or False. Below is an example of a condition:

45 equals 29. X

Of course, in mathematics, this is not true. Since 45 is a number with a different value than 29. Therefore, the above condition returns False, while below returns True.

A equals A. True.

In a Boolean logic (programming), True and False have corresponding values. Always remember, that True has a mathematical value of 1, while False has a value of 0. If you come to think of it, 1 and 0 are the accepted values of a computer, much more popularly known as Binary numbers. Now don’t disregard this very useful fact, since you might be handling complicated conditions in the future, and you may be able to take advantage of this information.

Now how are these conditions being used in programming?

Later you will be able to meet certain programming statements such as "If, Else, ElseIf", or "Do While, Loop", or "Select Case, or switch". These statements always follow conditions. Without conditions, you can’t put them to work. A simple explanation about how they can be used is as follows:

Perhaps you are to attend on a scheduled meeting. There are some things to consider especially those which depend on certain occurrences. You have prepared different sets of plans, which you designed specifically for a certain event. Suppose you have Plan A and Plan B. That, if there will only be at most 10 people to show up in the meeting, you will execute Plan A, but, if there will more than 10 people to attend the meeting, then you will proceed immediately to Plan B. Now there’s already the condition. Of course, with the set condition, if and only if that there are at most 10 people to show up, you will definitely execute Plan A, if not, then you go for Plan B.

In programming, these conditions are being put to code using Conditional Operators. Here’s a list of common conditional operators:

= / ==
Is equal to
>
Is greater than
<
Is less than
>=
Is equal or greater than
<=
Is equal or less than

There is also a conditional operator which negates any condition as listed above. This is the operator "Not", having a symbol in C / C++ as "!" or an Exclamation Point. Negation is by means of converting the condition into its opposite value. If True is being negated, then it becomes False, while it does the otherwise.

So, if you put the condtions given as example at the early part of this article into code, it should look like this:

45 = 49 (for Visual Basic) or 45 == 49 (for C / C++), returning False
A = A or A == A, returning True

If you have questions or perhaps clarifications, please leave ‘em all here. 

May 18, 2008

What are file extensions?

Filed under: Supporting topics

File Extensions or File Name Extensions are just the last N valid characters after the last dot (.) of a file name. These are popularly known to be required specifically in a Windows Operating System. Basing on this definition, you can actually rename a certain file and have a brand new file extension of whatever name you’d want it to have, except that you cannot use some characters such as ‘/’, ‘\’, ‘:’, ‘*’, ‘?’, ‘"’, ‘|’, and ‘ ‘ (spaces).

How are these file extensions useful?

Simple, it is to quickly tell the computer what registered application to handle it. Let’s take ".txt" for example. If you open a ".txt" file, by default, it will be handled by Notepad. Even so a file is not actually a simple text file, if it has a ".txt" file extension, it will be sent to Notepad by default. The reason why this has to be this way is because, Windows OS wanted to create an operating system that is very user-friendly. I tell you guys, if there were no file extensions, whenever a user opens a file, he would still have to manually specify whether what application to handle it. Now this can become a hassle in the part of the user.

How do file extensions work?

A file extension should be registered in the list of recognized file by Windows. Then, later, it would have to be associated to the application handling it by default. This is termed to be as "File Association". When you double-click to a file having a file name extension, Windows quickly finds an application that is associated to its file extension. In the case of ".txt", since Notepad is associated with it, then Notepad would have to be the application to handle it by default. Nowadays, there are lots of files which have internal trademarks to help the application associated with its file extension easily recognize it as a valid format. This is the very reason why there are some files having a ".mp3" file extension, when sometimes opened to an mp3 player, produces an error saying "Invalid format!". Some files have trademarks which are found at the end of the file. This is to secure that the file has been properly transferred from one directory to another and ensure that the file is not broken.

Try this one: First (if you’re running under Windows XP), open any directory. Go to "Tools|Folder Options". In the "View" tab, look for the option "Hide extensions for known file types", then uncheck it. This allows viewing of files in its complete name (which means, you can fully see the file name including its file extension). Look for a common file, suppose an mp3 file. Now a regular mp3 file should have a ".mp3" file extension. You should be able to see its complete file name with the ".mp3" at the end. Rename the file and make sure you change the ".mp3" into a common file extension such as ".txt". Open the file by double-clicking on it. The contents of the file is actually meant for mp3, but you will notice that, instead of an mp3 player to handle it, Notepad will be the one to open it.

Important: Sometimes, if a file is being opened forcely by an incorrect application, the application may cause the file to be damaged. In programming, there are a few ways to open a file: open it as plain text, by sequence, by random, by binary, and many more. The safest way to open a file without damaging it is by binary. Anyway, you never know how an application handles a file. So, to be safe, don’t change the name extension of a certain file.

May 17, 2008

What is a Programming Language?

Filed under: General Programming

As the term suggests, simply, programming language is just a language used for communication. We use English as our means of communication. This is actually a medium we use so that we can set a common understanding to other people. For us to be able to express ourselves in a proper manner, we use language. And at the same, we are being understood by those who also knew about language.

Now a programming language is what you will use to communicate to a computer, especially compilers (I might be able to tackle more about compilers later on). Since it is the only language a computer understands, for us to communicate to computers, we must learn this language. By doing so, we may be able to command the computer whatever we needed them to perform.

As of today, there are already a wide variety of programming languages. One of my favorite language is Visual Basic. There are also other languages such as C or C++, Java, and many more. These languages differ in syntax (or dialects plus accent). Of course, if you’re a Chinese, you won’t be able to communicate with a Japanese if you haven’t learned their language. It’s because the structure of their languages differ. It’s just the same with programming languages. How you write a Visual Basic code is different when writing a C++ code. But one thing’s for sure. No matter what language you use, can always come up to an application which may be able to perform lots of features and functions.

These applications (in the form of executables *.exe) are what we call as Programs. Remember these: Programmers, who are skilled in the field of computers, use a Programming Language. Now through the abilities of Programming Languages with the help of required corresponding compilers, they produce a final output which is a Program. The process of creating a program is what we call as Programming, or writing of source codes. If you have questions about these terms, just leave ‘em all here.

May 16, 2008

Welcome PL Geeks!

Filed under: Off-topic

Ever since I was in college, Programming was already my passion. Even though the first course I had wasn’t related to computer, I’ve already been studying programming. I’ve learned a lot of tricks and standards of programming, and I think I can already very well share to you guys how I do my stuffs in Programming Languages.

In this blog we shall be discussing topics of different programming languages. And I do hope you may learn from me. Thank you! emoticon

Get free blog up and running in minutes with Blogsome
Theme designed by Jay of onefinejay.com