sábado, 18 de septiembre de 2010

My praise for Python language

Disclaimer: PHP is my main scripting tool. I still prefer PHP for things related to HTML. Python threads looks like a total copy from Java's, but some concepts of Python have me dreaming too much...

I like when languages focus on both, problems and users. There are still many other common problems that bothers developers everyday, but I like like when solutions go towards freedom, instead of going towards constraints (although the world itself is a constraint).

Don't you find it rude to use Eclipse, NetBeans, VisualStudio or Zend Studio on EVERY computer you will ever use, only to check the a method's syntax? Programming environments should be cheaper and lighter... nevertheless, these comments looks contradictory...

When you unify several complex concepts into simple principles, you feel a surge of freedom in your brain, head, body, self, ... well, whatever you choose. Well, that's what I felt when I discovered that I can slice arrays the same way I slice strings.
  • If you have no text editor for coding, it brings Python GUI and a prompt to make tests.
  • It forces you to tabulate your code, which makes code looks nicer
  • Nested block delimiters reduced: neither {...} nor begin...end
  • help() and dir() functions: pass any object as a parameter and look.
  • The way you can access your own packages and modules
  • Built-in: highest integer number you can express is limited only by your computer
  • Built-in: complex number calculations (2+3i)
  • Its slicing system for arrays and string, for example: "python"[1:5:2]
  • dict.items() and enumerate(array)
  • Integer division for floating point numbers, without casting
  • You can use named parameters, for example: print my_page(head='Hello', foot='Bye');
Vaguely explored:
  • Its flexible object definitions. It looks more flexible than JavaScript definitions.
  • Lambda
  • Jython and binaries

martes, 14 de septiembre de 2010

Transforming If Conditions

I feel that breaking logic operations into several 'if' statements are easy to read and follow. But, from time to time I want to transpose them from single 'if' statement to multiple 'ifs' and vice versa. These are some patterns I use.

if(a==1) {
if(b==2{
f1();
}
}
/*AND*/ if (a==1 && b==2) { f1(); }

It looks a nice way to decompose a 'conjunction' (and); but it's not so well with 'disjunction' (or):

if(a==1) { f1(); }
if(b==2) { f1(); }
/*OR*/ if (a==1 || b==2) { f1(); }

But, if you have different conditions that execute the same statements, it's nice to know that you can join them with 'or'.

And now, there's one that annoyed me way too much, the empty 'if' block.

if(a==1) { /*nothing*/ }
else { f1(); }
/*NOT*/ if ( !(a==1) ) { f1(); }

I can remove that 'empty' block by negating the condition; but that extra parenthesis in NOT example looks odd. We can erase it by inverting that condition to:

if (a!=1) { f1(); }

And now, some other inversions of boolean operators:

if(a > b) ... if( !(a <= b) )
if(a >= b) ... if( !(a < b) )
if(a != b) ... if( !(a == b) )

It's fun to see that, if a number is not greater than another, it can, not be only lesser, but also equal; and that, if a number is neither less nor equal than another, then it's greater. Never forget the equal when inverting a less-than and greater-than operators.

Now I understand why the word NOT is never used in boolean variables. Which API method looks good: is_not_good() or !is_good()? Sorry for english language! ;-P

¿NOT is good? -vs- ¿NO está bien?

domingo, 12 de septiembre de 2010

Validation Overkill

"The price of reliability is the pursuit of the utmost simplicity. It is a price which the very rich find most hard to pay."
Sir Antony "Tony" Hoare, 1980

People keep inventing new ways of validation, and that's really good! The problem is when they want them all in the whole same form!

[This link] provides an example I have elaborated about what I have called "Validation Overkill."

I will list some overkill principles:
  • State validation constraints, before, while and after:
    before: by using a label, and description of the time of data and its formatting
    while: show errors while typing data, or when changing focus, with Javascript or AJAX
    after: it's normal that back-end rejects wrong data
  • Indicate validation errors. It's normally done by adding a red color to a data field
  • List a summary of errors with anchor links to data fields, normally at the top of the form.
  • Retell errors, just like the while part of validation constraints.
You are right! Of course these principles looks nice enough to take them into account, but there are some inconveniences:

Javascript problems: visibility, library size, duplication of validation code, excesive AJAX
  • Javascript code is visible
  • if libraries are big, they will take time to be downloaded
  • sometimes it's needed to validate twice: front-end and back-end
  • excessive ajax requests can kill bandwidth
User traffic and bandwidth: ajax
  • If your user base is big, it will be a load for your server
  • AJAX is a process running on back-end, not in the browser.
Processor power
  • You would like to squeeze the total capability of the machine, but
  • sometimes to pay for a CPU upgrade, or
  • to buy an extra CPU to use as replication could be a faster way to solve latency
And very important, amount of fields!!
  • because all these rules are present in every field of an input form,
  • and specially if those fields are required
But, as a friend of mine says: "That's what we are paid for!"

viernes, 10 de septiembre de 2010

Unanimous Rule

"What you have to do, done; and what you have to ignore, ignored. and don't cry for what you will lose."

I was thinking about how could I spend more that RD$ 10MM. A friend of mine said that he would help some people if he receives a great amount of money. In my case, I thought about making contests. I would choose a group of different ethnical people, and choice of the winner must be their responsibility.

I thought it could be a referendum. 70% of participants must agree on the winner. Or maybe the choice must be unanimous, and if someone is in disagreement, that person *MUST* state his/her reasons, and we'll ponder it until everyone is agreed.

One possible problem is that even organizers could cheat! Somewhat, I must interview them in a private and protect them from evil supervisors by controlling the tide of the contest.

I was also starting my ethnical group by creating my "Email Web of Trust", just like when I talked about ToDao: to create a way in which people trust me enough to show me some of their contacts to show the world what an unified group can make. people add you, and give you emails, and trust you.

It could be a voting, or by amount of friends, or branches. But, again, there are people who will fake any of these systems and votes. I, sadly, would force people to write captchas and to write some thoughts that I will analyze. I could force them to provide a phone number, an email, or a scan or copy of their identification number. I could even set up a webcam meeting with them to check their validity.

Do you find all of this as madness? (300 anyone?) Then read some Albert Einstein quotes:
  • "The secret to creativity is knowing how to hide your sources."
  • "I want to know God's thoughts...the rest are details."
  • "There are only two ways to live your life. One is as though nothing is a miracle. The other is as though everything is a miracle.
Every idea is a miracle, and you should annotate all of them; although this method of thought promotes schizophrenia. (I think Einstein would have said it like that.)

Why do I like Einstein? Because he proved the Theory of Relativity on physics. Just as we, in real life and HHRR say that "everything depends on the way you look at things"...

... and, in the end, I still have difficulties to find motivation to work on my duties. I'm almost sure it's because of my daydreaming. I don't know why, but right now I recalled a Franco De Vita song called Louis...

Sacrifice, Weapon, Recovery

Today, in The Great Pawn Hunter's web page, I was reading Decoy: Chess with Style, and then all the Knights section in the Lessons page. I re-re-leaned the forgotten sacrifice-weapon-recovery principle I learned in 2002. I was re-dazzled again about how nice and beautiful some sacrifices can become... and also, in how similar they are to some aspects of life.

You must notice that whatever you sacrifice is not in vain. A plain sacrifice, because it has meaning, it has a purpose.

In Naruto Manga, Asuma explains what is his duty in the village (a sacrificial piece) and who is the most valuable piece in his game of life. Shikamaru got it wrong until Asuma finally explained his thoughts.

These children of the atom are making great philosophical stories since Tetsuwan Atomu (Mighty Atom). Mighty Atom was renamed to Astro Boy in United States. What do you think could be the reason behind that name change?

And still those powerful robots can't imagine a world without money and wars, because they want to be heads and managers of Earth by keeping poverty... As Maquiavelli said, "It is better to be feared than loved", right? I wouldn't like to be respected by fear, or to be so powerful that I fear of being alone, without enough reliable people near me.

There's no enough imagination. We humans are so crippled that we can only imagine that this is the only one way to live our lives. Respect, tolerance, acceptance and communication.
Now, each one have needs, and exchanges or sacrifices to make.

Understanding between everybody is better than any kind of money. if I could communicate with all animals and bugs, I probably would not need to kill them. But they can't imagine a new civilization. (a song about this line?)

I know the risk of losing all good things I have achieved and kept. It's just like when I don't want to lose rating on Free Internet Chess Server (FICS), but if I don't risk, I won't improve.

I know that we need to push people to work and do things, and that is not easy to change from one way to another. But also, Creativity doesn't light up too well under anxiety or pressure. Each idea should be stored and pondered from time to time when they appear on our heads.

I think I wrote about "storing all ideas of the world, even crazy ones" some time ago, but I can't remember when It was. And I'm not talking about "Web of Ideas", but something else.

miércoles, 8 de septiembre de 2010

Happy -vs- Sad

#6: yes, randomness, e+motion, sell, task, That's our task. That's what we get paid for. We do it, change it, and tweak it as you like, and receive the blame for it if it doesn't work as expected. And still we need to be happy. But how convenient that Einstein said that "There are only two ways to live your life. One is as though nothing is a miracle. The other is as though everything is a miracle." Thank your for the miracle of working that way...

Do you think we should simply ignore that bad side? Why don't we celebrate when somebody dies? or when diseased? or crippled? Or better: don't think about it at all! Show indifference to your friends' suffering, because it's bad and we should be in good mood forever, right? No! because they will reduce their estimation towards you. Challenges, Families, Relationship, Friends, ... the silly "That's another thing" answer. I hate it. I believe in Universal Law. Law should be applied to every[thing|one|where]. Then, What would my penalty be?

If you believe in God, then you believe in supernatural powers. If not, well, Malcolm X said that "a man who believes in nothing will fall for anything."

martes, 24 de agosto de 2010

Autist Cowgirl

I saw Temple Grandin. It's a comedy movie, right?

She knows that humans care about cows because they are food, and so they will be killed. Nevertheless, she also thought that cows deserve some kind of respect. She also said that if she were to die, she would like it to be in the best and most peaceful way possible...

Have you read the previous paragraph? Many of you could think "Cows are not human. Why should we treat them as humans?" Well, I don't know what you could think about random citizens, workers and soldiers, but they also are/will be "killed" (citizens will be taxed, workers won't have enough freetime, and soldiers will go to wars), but that doesn't matter, because they are not cows, but sheeps of some big shepherds.

My favourite phrases from the movie:
  • People. I don't understand people ...
  • She thinks in pictures.
  • They mess with the perspective!
  • Think of it as a door ...
  • It's almost time for The Man from U.N.C.L.E.
  • Nature is cruel, but we don't have to be.
  • I touched the first cow as it was being stunned ...
  • I don't want my thoughts to die with me.

jueves, 19 de agosto de 2010

Pulpy Enough

I saw Pulp Fiction. I think this movie was made with several kind of people in mind, because part I didn't like much, I'm sure those same parts will be lovable for women, delinquents or polices.

Each one of these phrases are very related to parts I like. There are many phrases, so I only stated those memorable ones for me of the whole section:
  • Royale with Cheese.
  • Eenie, meenie, minie, mo.
  • "Please" would be nice.
  • All right, now, Yolanda!
  • ... shepherd. (I avoided the temptation of putting that complete "ending" phrase)
As dreamy and delightful as Kill Bill 1 & 2 were.

miércoles, 18 de agosto de 2010

Function's Name, Code and Usage Relationship

To show how important the relation between a function's name, code and usage is, let me show you this silly example using Python:

#Look this valid function definition:
def are_different(a,b):
return a==b

#This line looks nice. They are different:

if are_different(1,2):
print "1 & 2 are different!"
else:
print "Houston: we have a problem!"
#Huh? Where is the mistake?

raw_input
("Press [ENTER] key...")

(You can download previous code in this link. Double-click to run it.)

What can you see? It's fun to see how function name says one thing, and its implementation says another.

Conventions are important. It should be clear by reading any part of the code.

In validation functions, there are two possible values. True and False. Although you can choose to return the one you like the most, when you want to say that a validation has_failed or has_passed, it "should" be clear what value to use, shouldn't it? ...

Actions (or processes) should be according with names. Names should be chosen according to actions. "What you say should be backed-up with what you do." "Things you do speak louder than things you name."

Comparing this with Positivism, I like how inspiring messages are written, although they don't promote planning.

#300-private

martes, 17 de agosto de 2010

What Programming Languages contribute

Each programming language should contribute something new to the programming world, like some kind of new element to the structure of a program, to name a example. An inconvenient I have is that I still see sequential solutions easier to find than a structured ones.

My programming rabbit hole started when I was 14, with slight touches toMS-DOS command prompt. Then I lightly met FoxPro, then COBOL, until I hit Turbo Basic.

I learned that Assembly Language existed, the one I consider the genesis of imperative programming language style. When you notice that Assembler is essentially data movement and comparison, it's hard to imagine something like Warcraft coded in this language. Some time ago I learned that programs are based in a theoretical Turing Machine.

When I saw function and sub statements in QBASIC and the list of commands of the Help, I knew that something different was comming. Something called procedural or structured programming. In college, I saw DBASE III Plus (which I compared with FoxPro), Turbo Pascal and Borland C. I saw in the last two some resemblances to QBASIC, but declaring variables and importing libraries where something new to me.

In the university I learned what was the real importance of C and Pascal, why GOTO is evil, complex typedef struct, and recursion, that by itself was something too abstract for me, not to mention the fact that it's needed for some sorting algorithms (also abstract) like Quick Sort. I wish I had met SmallTalk and LISP at this time... I feel power and flexibility in LISP, but I still neither understand it, nor its macros.

In 1995, the first language I saw after QBASIC was HTML, but I didn't see some statements (no conditions, no loops, no variables). So HTML was not programming language for me, and I rejected it until I learned about JavaScript. Something interesting that I learned with JavaScript is that you can "store" function definitions in variables, but later I learned that what gets stored is a reference, and that C allowed this kind of assigment. About JavaScript events, I heard of the event concept with Visual Basic (QBASIC successor) and Delphi (Pascal's).

OOP... What a headache!! I was doing a lot of HTML, CSS, JavaScript and PHP, before I learned about OOP and Java. I saw C++ before, but I never saw something about Object-Oriented Programming on it. I learned that SmallTalk was an older OOP language than Java. Inheritance, abstraction, polymorphism, encapsulation, imports (I took them like includes, but later I learned that they are namespaces!), collections, threads, bytecodes, and patterns: all of these were part of the tsunami that Java was for me. Some interesting things that I tested with Java for Eclipse were Test-Driven Development and Source Navigation (like navigation in Internet)

If something was difficult after starting to learn Java, it was to learn CakePHP and the concept of MVC Frameworks. It's nice to jail a group of developers into conventions, but the problem is when the framework doesn't provide what you need in a way that is easy, accesible and well documented.

A problem I get with JavaScript is when I want to access some local variable, inside a function called from another function. In C# there is something called closures, designed to avoid this kind of problems.

I wanted to experiment something new, so I looked into Ruby, and then Python. I choose Python because of how it does things and it tends toward procedural and imperative styles easier. Not to mention Python IDLE. What I discovered is that code blocks are delimited by tabs or spaces, but the flexibility of its dynamic typing was a good pay-off for me. I later knew that FORTRAN was also space-delimited for code blocks. Python use import for namespaces, but here, they are are real plus!

The first time I heard the term lambda was when I learned what is the Haskell language. This is a concept vaguely experimented by me, but it's a pending one.

ASSEMBLY speed never will be 100% matched by compiled languages, but his drawback is his bad programming productivity.

FORTRAN was the most used language for Math.
LISP seems so flexible and so abstract that it looks boring.
C focus on Implementations to increase Portability.
SmallTalk was the first famous OOP language.

Now we have Haskell, Scripting Languages, C++ and Java. It seems like including several new libraries and constraints, and also change the semantics of old languages. But how could you use the power of LISP without never ever using parenthesis? or fixed-width? or brackets? or tabs? or begin/end blocks? If you can solve the problem of Hierarchy of Operators without using any of these block delimiters, please show me that novell discovery! But not bring another one.

Now, I think that the next step would be a language that could abstract or force segregation of the many individual areas of a program in a meaningful way. MVC Frameworks are a great example, but not wide and crystal-clear enough. I think that OOP is for Programming the same that Calculus is for Math.

There are things like SSH and HTTPS that are standard and globally "accepted". So, why can't some essential authentication structures come by default in some languages, just the same objects like System, String, Math, Thread, etc. exist?