April 19, 2012

Scope precedence (from function perspective)

Scoping. Very common topic among CF developers.
Which scope has precedence? When and why I should scope variable?
No matter how many times I read or heard answer on these question, no matter how many I answered to myself, I always forget it after few months.
Thus I decided to find a way how to remember it once and for all :)
Magic formula (for me) is in answer: "Scope precedence is same as it is in Java"
Here I talk only about precedence from function perspective.
Inside method (function) body we deal with 3 major scopes (fake this I'll ignore)

Argument scope - hold references to function arguments
Local scope - hold references to local variables, variables declared (vared) inside function body
Variables scope - it contains references to protected instance variables

In same order scopes are listed here, Adobe ColdFusion 9.x (and I beleive Railo 3.x) will go through when looking for variable referenced inside function body. This means:
Referenced variable, which is not explicitally scoped inside function body, ACF first look for in argument scope, then if it could not be found there, in local and, at the end, in variable scope.

At the same time, we should have 2 things in mind :
1) Local variable cannot be named same as argument (same as in Java)
2) CF, as dynamic language with weak typing, allows dynamic argument list which means, that argument does not need to be defined, unless it is explicitly set (required = true)

Example 1: Argument value not set

 myVar = "instance variable value";
 //no default value set for argument myVar
 function myMethod(myVar){
  myVar = myVar;

new ScoptinTest().myMthod();

"instance variable value"

Example 2: Argument value set

new ScoptinTest().myMethod("argument value");

"argument value"

From these examples, we clearly see, if we don't explicitly scope variable:
a) If argument is not defined, instance variable will take presedence
b) If argument is defined, it is going to take presedence

To summarize:
1. Argument and Local variables shares the throne (there can be only one)
2. Variable comes right after

Knowing this, much less characters we'll write in the future and much less noise in the code.

July 18, 2011

The Last Programming Language (my 5 cents)

This started as comment on Sean's review of Uncle Bob's preso "The Last Programming Language" and outcome had too many characters and convert it to blog. Anyway, I blog quite rarely, it's been about timeto finally make one in year 2011 :)  So, to understand what I am talking about you should go and see Bob's preso first.

My 5 cents

I don't dare to predict which or what kind of language will take the throne.
No matter I am familiar with most mentioned languages, and have working expirience with some, I really it is need much more then that to be able to elaborate on that. However, I see numerous other reasons why we, humans, will settle on one (uber, last, ultimate, call it however suits you the best) programm language. Because, it's in our nature. To illustrate it, I'll use popular analogies.

Safe side
Software development is too important discipline in today's society that this level of freedom is "unacceptable" (sounds hursh I know). These days is very popular to compare software with civil engineering, so I'm going to do it too. CE students are teached to do things in certain way. These ways guarantee acceptable level of quality of their products. Most civil engineers will blindly apply what they've learned and stay on safe side.
Doing better then that means balancing project expense and construction quality, in context of reality (moment).  Simplified, in most cases, it means better quality for less money. Also, knowing when to increase expense in favor of better outcome is quality for itself.
OK. You can always say "This is so rigid because human lives are at stake". True, but is it really that different with software engineering? What controls medical equipment and modern building machines? What civil engineer use for calculations and designs? What will descrease (or increase in rare cases :)) saldo on your banking account?

Common ground
Proponent of freedom and diversity use variety of speaking languages as an example. World "live" and communicate with so many different languages, so why it can't use more than one programming language.
English language is perfect contra argument. No matter do you like it or not, but this is de facto communication standard among professionals (of any kind). See? I am just doing it :) No matter french is more "singy", spanish sexier, italian simpler, chinese more descriptive, we settle (spontaneous or not, nevermind) on english as common ground.

Software development is not just coding
People are afraid of becoming bored, by time (through decades), working with one language.
First of all, language is just a tool. As such, it just helps you, assist you, to reach your goal.
And our goal is well crafted software. Standardizing laguage, gives me more time to focus on architecture and design. From perspective of tools, Eclipse seems as solid example. Common platform that suits the needs of most programmers.

To conclude.
I am quite sure it will happen by time. Is it going to be some mutant of functional PL or not, to me, is not important at all. Our profession is young and mature by time. Why it should mature in much different way then all other (centuries old) professions?

June 20, 2010

Learning Scala

As a man who try to follow goals of pragmatic programmer, learning Scala is one of investments in my portfolio and new language this year, as well.

I am a man of practice. Therefore, I like to learn is from examples. Brute force exercise of this principal is "Learning Scala in small bites" blog, as well I place I would recommend for start. To be able to remember or comprehend things, I always try to pass through fingers all I read. This case was no exception. To be honest, I didn't follow this rule all the time :)
Now when I poisoned my brain with a bunch of raw information, next move was to spice it with some explanations and more usable examples. Next address was IBM and "The busy Java developer's guide to Scala" series of articles by Ted Neward.

So far, I like Scala a lot. One of those languages that caught me on the first site. I have no experience with functional languages, but how Martin Odersky has incorporated its principals into object-oriented world is something I grasped(?) very easy.

UPDATE: Upffff. This is THE challenge! Just when I thought I'm moving/learning fast, an totally non-understandable example hit me in the face:)

March 22, 2010

What if I don't care for Flex Builder?

"Everyone" point out how $299 for CFB is a good deal because you get Flex Builder bundled. But what if I don't care for Flex? Is it still a good deal?

Flex Builder Standard costs $249 and CFB+FB $299. What is a real idea behind this? To promote CFB among Flex developers? Honestly, I see this as a better deal for Flex developers, who really needs an IDE for rapid development, then it is for CF developers (only).

Me, as CF developer, don't see this as a good opportunity at all. Opposite. 83% of money I'll pay, actually goes to something I won't use.

On the other hand, by supporting this project, we keep doors open for version 2 one day. And when that day come, I hope that CFB will be sufficient argument for itself to have decent sale.


Simple math:
Flash Builder 4 Standard (stand alone) - $249
CF Builder 1.0 w/ Flash Builder 4 Standard included - $299
-> CF Builder 1.0 costs $50

Related content:

March 16, 2010

BlazeDS: Creating endpoint at runtime

Why? Because I do not want to bother end users with xml configuration files. Simple as that.
Biggest enemy of your application is user itself. Therefore, reducing possibility to make a mistake is most important goal if you wish to left good impression with your app. This was one of steps that I take on the road to make Collyba installation procedure as easy as possible.
As I said in previous blog, while I was working on this, insight  to BlazeDS source files was of great help. Actually that is where I found a solution.

What are channels and endpoints?
Channels are client-side objects that encapsulate the connection behavior between Flex components and the BlazeDS server. Channels communicate with corresponding endpoints on the BlazeDS server. You configure the properties of a channel and its corresponding endpoint in the services-config.xml file.
But in our case, we won't configure it in XML file but programmatically.