Quote  |   15 September 11 | 18 notes

If you don’t succeed, call it version 1.0.

Text  |   7 September 11 | 7 notes

So long Pal!

One of the most discussed examples in Computer Science classes is the palindrome. Wikipedia defines palindrome as a word, phrase, number, or other sequence of units that can be read the same way in either direction, with general allowances for adjustments to punctuation and word dividers.

According to one article, palindromes were discovered as early as the 79AD where the latin phrase “Sator Arepo Tenet Opera Rotas” was found as a graffito at Herculaneum. However, it was found out that palindromes of considerable complexity were explored in the ancient Sanskrit poetry.

Palindromes are usually discussed in computer science classes because it poses a rather easy problem for students to tinker with. The most common example of a problem involving palindromes is checking whether a given string is a palindrome or not. Here are 3 different ways to check if a string is a palindrome(NOTE: The methods posted assumes that the string be a one-word string and does not include punctuation and word dividers.)

Code #1

public boolean isPalindrome(String word){

    boolean isPal = true;

    for(int i=0; i<Math.floor(word.length()/2); i++){

        if(word.charAt(i) != word.charAt(word.length()-1-i)){

            isPal = false;

            break;

        }

    }

    return isPal;

}

Explanation:

The method loops until the middle of the string and compares the character found at the value of i and compares it to the character with the same index if the string is reversed. If all characters are equal, then the string is said to be a palindrome

Code #2

public boolean isPalindrome(String word){

    boolean isPal = true;

    String rev = “”;

    for(int i=0; i<word.length(); i++){

        rev = word.charAt(word.length()-1-i) + “”;

    }

    if(!word.equals(rev))

        isPal = false;

    return isPal;

}

Explanation:

The method reverses the string and stores it in another variable. The method then compare the original string and the reversed string. If the two string are equal, then the string is said to be a palindrome.

Code #3

public boolean isPalindrome(String word){

    boolean isPal = true;

    Stack<Character> stack = new Stack<Character>();

    for(int i=0; i<Math.floor(word.length()/2); i++)

        stack.push(word.charAt(i));

    for(int i=Math.ceiling(word.length()/2); i<word.length(); i++){

        if(word.charAt(i) stack.pop()){

            isPal = false;

            break;

        }

    }

    return isPal;

}

Explanation:

The method uses a stack, a Last In First Out data structure, and stores all the characters until the middle of the string. The method then pop each character from the stack and compare it to the character corresponding to it on the 2nd half of the string.

DISCLAIMER: I didn’t test if the Java codes are working. It may cause some syntax errors but the algorithm will definitely work.

Video  |   5 September 11 | 4 notes

fuls:

Word Lens — http://itunes.apple.com/us/app/word-lens/id383463868

Word Lens can instantly translates printed words from one language to another using the video camera on your iPhone. No network delay, no roaming fees, and no reception problems.

THIS IS AMAZING!

Reblogged:

Video  |   31 August 11 | 10 notes

ubersuperduper:

This is the Wacom Inkling which aims to merge the digital and traditional creative process in a bold new way. 

From Wacom’s Product description:

“The Inkling digital sketch pen captures a digital likeness of your work while you sketch with its ballpoint tip on any sketchbook or standard piece of paper. Designed for rough concepting and creative brainstorming, Inkling is ideal for the front end of the creative process. Later, refine your work on your computer using an Intuos4 tablet or Cintiq interactive pen display.

In addition to capturing your sketch, stroke by stroke, Inkling allows you to create layers in digital files while you sketch on paper. Digital files are transferred to your computer using the Inkling Sketch Manager software, and later, exported to applications such as Adobe® Photoshop® and Illustrator®. Files can also be opened with the included Inkling Sketch Manager software to edit, delete, add layers or change file formats.”

Can’t wait to try this out some how though being restricted to only ballpoint pen is a bit of a bummer. 

via. Comics Alliance

This will change the world.

Reblogged: ubersuperduper

Text  |   10 August 11 | 17 notes

Wise words

jafetsanchez:

“If you want to be a good programmer, you just program every day for two years.

If you want to be a world class programmer, you just program every day for 10 years, or take the “Analysis of Algorithms” class and program for two years.”

By Prof. Erik Demaine at M.I.T.

Reblogged: jafetsanchez

Text  |   7 August 11 | 9 notes

Best code comments ever encountered

ramiismail:

Best code comments ever encountered

// 
// Dear maintainer:
// 
// Once you are done trying to 'optimize' this routine,
// and have realized what a terrible mistake that was,
// please increment the following counter as a warning
// to the next guy:
// 
// total_hours_wasted_here = 39
// 

LOL. This is funny. :))

Reblogged: ramiismail

Text  |   28 July 11 | 7 notes

The Principles of Good Programming

codingstandards:

an interesting article from  http://www.artima.com/weblogs/viewpost.jsp?thread=331531 written by Christopher Diggins the last
July 24, 2011

 The principles of good programming are closely related to principles of good design and engineering. The following programming principles have helped me over the years become a better programmer, and I believe can help any developer become more efficient and to produce code which is easier to maintain and that has fewer defects.

DRY - Don’t repeat yourself - This is probably the single most fundamental tenet in programming is to avoid repetition. Many programming constructs exist solely for that purpose (e.g. loops, functions, classes, and more). As soon as you start repeating yourself (e.g. a long expression, a series of statements, same concept) create a new abstraction. http://en.wikipedia.org/wiki/Don%27t_repeat_yourself

Abstraction Principle - Related to DRY is the abstraction principle “Each significant piece of functionality in a program should be implemented in just one place in the source code.” http://en.wikipedia.org/wiki/Abstraction_principle_(programming)

KISS (Keep it simple, stupid!) - Simplicity (and avoiding complexity) should always be a key goal. Simple code takes less time to write, has fewer bugs, and is easier to modify. http://en.wikipedia.org/wiki/KISS_principle

Avoid Creating a YAGNI (You aren’t going to need it) - You should try not to add functionality until you need it.http://en.wikipedia.org/wiki/YAGNI

Do the simplest thing that could possibly work - A good question to ask one’s self when programming is “What is the simplest thing that could possibly work?” This helps keep us on the path towards simplicity in the design.http://c2.com/xp/DoTheSimplestThingThatCouldPossiblyWork.html

Don’t make me think - This is actually the title of a book by Steve Krug on web usability that is also relevant in programming. The point is that code should be easily read and understood with a minimum of effort required. If code requires too much thinking from an observer to understand, then it can probably stand to be simplified http://www.sensible.com/dmmt.html

Open/Closed Principle - Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification. In other words, don’t write classes that people can modify, write classes that people can extend.http://en.wikipedia.org/wiki/Open_Closed_Principle

Write Code for the Maintainer - Almost any code that is worth writing is worth maintaining in the future, either by you or by someone else. The future you who has to maintain code often remembers as much of the code, as a complete stranger, so you might as well always write for someone else. A memorable way to remember this is “Always code as if the person who ends up maintaining your code is a violent psychopath who knows where you live.” http://c2.com/cgi/wiki?CodeForTheMaintainer

Principle of least astonishment - The principle of least astonishment is usually referenced in regards to the user interface, but the same principle applies to written code. Code should surprise the reader as little as possible. The means following standard conventions, code should do what the comments and name suggest, and potentially surprising side effects should be avoided as much as possible.http://en.wikipedia.org/wiki/Principle_of_least_astonishment

Single Responsibility Principle - A component of code (e.g. class or function) should perform a single well defined task.http://en.wikipedia.org/wiki/Single_responsibility_principle

Minimize Coupling - Any section of code (code block, function, class, etc) should minimize the dependencies on other areas of code. This is achieved by using shared variables as little as possible. “Low coupling is often a sign of a well-structured computer system and a good design, and when combined with high cohesion, supports the general goals of high readability and maintainability”http://en.wikipedia.org/wiki/Coupling_(computer_programming)

Maximize Cohesion - Code that has similar functionality should be found within the same component.http://en.wikipedia.org/wiki/Cohesion_(computer_science)

Hide Implementation Details - Hiding implementation details allows change to the implementation of a code component while minimally affecting any other modules that use that component. http://en.wikipedia.org/wiki/Information_Hiding

Law of Demeter - Code components should only communicate with their direct relations (e.g. classes that they inherit from, objects that they contain, objects passed by argument, etc.) http://en.wikipedia.org/wiki/Law_of_Demeter

Avoid Premature Optimization - Don’t even think about optimization unless your code is working, but slower than you want. Only then should you start thinking about optimizing, and then only with the aid of empirical data. “We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil” - Donald Knuth. http://en.wikipedia.org/wiki/Program_optimization

Code Reuse is Good - Not very pithy, but as good a principle as any other. Reusing code improves code reliability and decrease development time. http://en.wikipedia.org/wiki/Code_reuse

Separation of Concerns - Different areas of functionality should be managed by distinct and minimally overlapping modules of code.http://en.wikipedia.org/wiki/Separation_of_concerns

Embrace Change - This is the subtitle of a book by Kent Beck, and is also considered a tenet of extreme programming and the agile methodology in general. Many other principles are based on the concept that you should expect and welcome change. In fact very old software engineering principles like minimizing coupling are related directly to the requirement of making code easier to change. Whether or not you are an extreme programming practitioner, this approach to writing code just makes sense. http://www.amazon.com/gp/product/0321278658

A very interesting article. Reminds me of one of my classes last semester.

Reblogged:

Likes

kontantkort