Wednesday, February 15, 2012

Functions with Multiple Exits

Dr Bob suggests that multiple exit points make a function harder to maintain.

With respect this is one of the few times when I completely disagree.

For any function call the best practice is to validate all inputs, do some calculations, and then do the main event. At each step in the process we have a potential for an exit.

Is the input invalid? Exit
Is the calculation out of range? Exit.
Is there a trivial answer? Exit.

The goal of an early exit is to make code run faster. Test for the simplest possible answer and take that exit if you can. When I teach this I always tell people the first and most important question we ask ourselves all the time is "Are we done yet?"

Some people like to set a flag in the code. Loosely pseudocoded as:
if (some dumb stuff) then
Error:=1;
End if;
More code
if (Some more dumb stuff) then
Error := 2;
end if;
More code
if (error > 0) Then
result := Error;
else
result:= myResult;
end if;
Return result;
End function;

Some how this is said to be less clear than
if (some dumb stuff) then
Exit(1);
End if;
More code
if (Some more dumb stuff) then
Exit(2);
end if;
More code
Return myResult;
End function;

Well, I think the answer is clear just from the pseudocode. But the discipline to code that way takes some practice. In this example it isnt really all that bad, but in practice all those ifs get pretty crazy. We end up deep inside a loop or some calculation, find an error somewhere in left field and then have to code a bunch of flags from deep deep. The flags usually end up making a mess of the code, and so instead programmers throw lots of exceptions when they should just return a valid value. I cant remember how often in code reviews I have punted a function definition because it needed to return zero or something as a valid result instead of throwing an exception. I am a sticker for results and wonky function results are not acceptable even if the pain of making them is quite large. Now we have a language construct to help us. Will it get abused? Ofcourse. But it will also make code clearer when it is applied well. At least the intention is clear with Exit(x); There is no where else to go but out of the function call. If we need to play with variables, flags and conditionals to force execution stoppage that will definitely add to the fray.

Now I need to figure out what happens in a try .. finally block that has an exit. I hope the cleanup code runs. Pretty sure it will.


Components: install: reinstall: and again.

The problems with installation of third party components begin when the premises of Delphi are forgotten, or when too much help is offered. TMS Software offers an amazing collection of stuff. They are not the only component set I bought but they are the biggest.

Components have 2 parts. Design time, and runtime. The design time stuff usually works flawlessly, but somehow runtimes are more problematic. The library has to find the path to the runtimes, but the design time stuff is managed by the compiler. As soon as people have options, the fun starts. Adding Microsoft benevolent dictatorship to the mix with ever changing rules about what can be installed where and the proverbial dog's breakfast ensues.

Delphi XE2 is cross platform, multiple compilers with multiple targets. It is also multi-lingual with a lot of stuff in several languages, not just english.

Is that a challenge to keep straight? You bet it is.

Evening three of the installation has me gasping for breath. There are so many things to install and configure.

I started out putting stuff on the network drive. Turns out that is a no-no.

Uninstall number two happened when I tried to use the setup.exe that came with programs. Some stuff breaks when it is not installed in the default location.

Uninstall number three happened when I read the directions for manual installation wrong, and just ended up with the runtimes some how. Still not sure what went wrong there.

But forth time lucky. Now I just have the specialized packages for CE and the web stuff to go.

I got a bit upset for nothing when I found that TMS Unicode was 32 bit only. Then I realized that I probably dont need them because CE2 has it already. Oh well, if I dont use them it is simple to uninstall.

The process continues. TMS Instrumentation Workshop looks so cool. The components are sweet too. Smooth animations are something I want to play with.




Delphi XE2 Enterprise

I am jumping back into Delphi again after years. I decided to blog the experience.

History: My story When I left San Diego more than ten years ago I had a fresh copy of Delphi 5 in my truck load of household belongings. The language was fresh and exciting, even though that version was a bit old, and I had not touched it in a year and a half as I moved more into architecture and database work.

Good intentions to go back and dig out the CD, install it and resurrect my old passion for coding met with no real success. Oh I did a lot of coding in other languages. But my focus remained on Architecture and in large measure it still does. But when I looked over at the latest and greatest Delphi offering I saw a jumbled mess of dot net and windows coding that seemed to try to go in every direction at once, but failed to be convincing in any of them. In short, the team had lost it's focus. They didnt really know how to drive the ship any more, and it was a mess.

History: Wandering around a bit This was not a compelling story for me. Distracted with many responsibilities and digging deeper into ERWin, data modeling, and deeply understanding client's needs took all my energy. Someone wrote a book about it. As Eric Evans worked on his great lakes shipping project, I sat in San Diego and worked on a few projects. We had a few developers in common as people came and went and I heard a lot about this guy from the east who thought a lot like I did about software design. At the time I was famous for 'taking too long to get started' on every project. A few years later Evans wrote his classic “Domain Driven Design” that explains why. Everyone else was exploring design patterns and talking about the roots of architecture at the time. The thing that impresses me the most about DDD over any other approach is that it deeply understands how people work. So it doesnt try to put peoples round heads into square boxes that dont fit.

Soap Box Sermon: Architecture Nothing about software design and development will ever be really easy. Most real developers dont care about how hard it is. They are excited to know it is systematically possible given a vast amount of effort. Mere mortals who need a social life need not bother. There is far more sweat and pain involved in programming than in any other intellectual discipline. Some people think lawyers have it hard. Law is a trivial joke in comparison, Programmers know everything about everything, or they know where to look. There are no appeals. Even mathematics allows for an occasional jump to conclusions.

Taking a look at the meandering romp of a path my so-called career has taken you will find that it covers a lot of ground. So far what you have seen of my writing style will lead you to a perception that I am at once reflexive in thought, and all together all over the map all at once in my dialogue. Does it make it hard to follow? A lot of people will have given up already just because the train has wandered so. The people who read and love the organic; casual but deeply thoughtful consciousness are the ones who will persist through these musings any way so there is little point in creating a pedanticly structured analytically dry-as-dust academic tome. Although I have been persuaded to write that way on occasion by persistent co-authors.

Soap Box Sermon: Delphi And yes, Delphi was a mess in those days. This can sometimes be helpful if it is an organic mess of comfort and ease, where the clutter has a familiar nested feel and the ritual routines are purposeful, non-taxing and sociable. But in those days none of that was true of Delphi. Dot net is constitutionally a valley of pain and arbitrary big brotherishness borne of too many egos, too many compromises, and just plain bigness of britches. Even the 4.0 offering is barely good enough. It is a world for IT egos that need entire valleys full of digital serfs to bend, staple and mutilate long long long toilet rolls full of code just to put a few controls on a form. Architects who insist on dot net, or the even bigger dirtier toilet rolls of Java mumble incantations about security, cross platform, multi-tier (or multi-wet bawling agonies in Java) Enterprise design patterns, and Ood. All of this was simple stuff in Delphi 5. In fact we could do it without writing much code. And it worked pretty much flawlessly. The only problem was Borland couldnt leave dot net out of the picture. They had to muck in the latest and greatest. And much ado was made about … nothing good anyway.

Viva la difference; eventually All this mess lead me to dismiss Delphi. Then 3 years ago the light began to appear as Borland gave up the code. Embarcadero did not endear me at all. The business plan was and is tough stuff. They want to get paid. Well so do I. And then they did something crazy that I loved. They promised to deliver on it, to make it worthwhile to live with the tough business plan and make a deep investment again.

Return to the main point: Clarity. Focus. Vision. A plan. And no more mucky dot net. That was 2010. I was seriously thinking it would be great to go play in my old sand box again but the price was a bit high. Well, that was then and now FireMonkey. A friend of mine who once worked on the deep core of Crystal Reports (Hi Drew) said any product that combines the words Fire and Monkey has to be great stuff for programmers. Well yeah, but sexy cross platform development that lets you do good MVC design but doesnt INSISIT on it also great for programmers.

Ubbersmartness culture Delphi was always a great patient teaching language because it made stupid hard to do, and smart was always easier. Really clever and really cool is part of the culture of ubersmarts that I love. Or at least a few emails and 3 tricks that got turned into a component eventually smart. And that was and is fantastic. Now cross platform at the bare metal is killer if it works. So what do I think so far? Were back!

The pain of commitment I laid out four grand on XE2 Enterprise, component packs from TMS etc. and I am jumping back in head first with money out of my own pocket. I dont expect anyone else to get it yet. I cant expect bosses who have never heard of it or seen it go do much to help out. As it is I consider myself fortunate to be able to buy now and pay for it on an employee purchase deal. It might seem crazy but I love programming, and I hate writing the same code over and over and over. I can do SO MUCH STUFF with this thing...


Tribute to my bud N8 So as a few Canadian friends say at such an inspiration 'Lock and load baby, were goina hunt us some bear.' In case you are not inclined to regard such low brow enthusiasm with encouragement, I can only offer a simple but equally cultured epithet. Build a bridge and get over it.

Monday, April 13, 2009

It is time I posted some of my comments from the Red course here. The most important post is this one:

Reading scripture it is pretty obvious that the sermon preaching model was important, but when ever REAL teaching happened that meant more in the long run for all of us, it was intimate. Our Lord had few words for the large crowds; many for the intimacy of the disciples. We should emulate Him.

The preacher in the pulpit is an innovation that happened after those days. In the synagogues of Jesus day as it is today, the service was shared and often was the way news was transmitted. Travelers were encouraged to share. In our day we feel so inundated with 'news' that we insulate from the world and our leadership are gatekeepers and filters protecting the community from anything that might be different or out of step with their well ordered set ideas of what is appropriate. As a result the very thing they are protecting becomes the cause for a new denomination, a new congregation, a new expression less rigid, more fluid.

But worse, we find ourselves doing exactly the opposite from what our Lord wants. We make our world smaller, our circles of friends closer to our own ideas, and our defensiveness a cause for celebration. The Pharasies were accused of this kind of thinking. It is natural but that does not make it right. Jesus was popular as a teacher because He did not cut people off, He did not ridicule their expression of God and the Kingdom of God. But He did teach and preach to give people power, to help them understand, to fire their imaginations, to serve them deeply and effectively by taking the raw materials they gave Him, their strange ideas, their broken hearts, and He molded them shaping a new hope from that brokenness. 

We have the same chance to do the same task today. But to do it well we need to understand God's word the way it was written, with the intent and ideas well understood from the Hebraic perspective it was written in. Our present Christian interpretation is very Greek. It is based on the ideas of Plato more than those of Christ ! There is a viable Hebraic way to view the whole of scripture. Greek texts were written with a Hebraic mindset by Jews who understood their Jewish master. We need to get back to that understanding as best we can. And there are excellent tools to get us there. There is a 5 year weekly Bible study I know of that goes carefully through these ideas. 

Relating our personal stories to the scripture is important. Understanding what is in the scriptures the way it was written, without the traditions that grew up around the faith with all the politics and cultural baggage of the western mindset is vital. I pray we consider embracing an ancient oriental mindset. A very different way of thinking, but one familiar and heart warming from the deep beauty of the scriptures we love. And our motivation for doing so, to find the real Jesus, His real world, His true expression. To do it His way. If you think Jesus and His ancient ways fit in our modern world think again. How would you and your ways fit in the world of His incarnation? How can we know the message if we don't know the world? To know in ancient Hebrew was not a matter of intellect. It is the highest form of intimate loyalty. Abraham knew his wife Sarah and they had children.

God's greatest promise; The new covenant of Jeremiah 31:31. Read it. Jesus means Jeremiah 31:31 when He talks about the New Covenant in His blood. But if you read it don't take it as allegory. That is Greek thinking. Take it as literal. There is no need for allegory in that passage. All literal interpretation means for this passage is that it is not yet fulfilled. But we have the first fruits of it now in you and me.

Tuesday, February 24, 2009

Life is too short

A friend of mine is in grief. His daughter wrote what I am posting below. And then she died. Age 24. My friend is in grief. For him life goes on but not really living. Not yet anyway.

I will offer a prayer my friend does not understand. He does not worship God in Hebrew as I do. This prayer is sometimes called  the prayer for the dead. But it is really the prayer for the living who remain. It is also sometimes sung or said in Aramaic. This is the opening stanza transliterated:

Yitgaddal veyitqaddesh sh'meh rabba
B'ʻal'ma di v'raʼ khiruteh
v'yamlikh malkhuteh
v'yatzmach purqaneh viqarev m'shicheh
b'chayekhon uvyomekhon
uvchaye d'khol bet yisraʼel
b'ʻagala uvizman qariv v'ʼimru amen

Translated:
Exaulted and is God's great name
in the world which He has created according to His will
and may He establish His kingdom
may His salvation blossom and (draw) near
in your lifetime and in your days
and in the lifetimes of all the house of Israel
speedily and soon, and say Amen

Below are my friend's daughters words. Thursday is the aniversary of her passing:

The story of Job shows us that God is in control, and he does not initiate evil, permits it but also limits it.

There are two common responses to suffering:

Stoic cynicism:
- ask why me?
- there must be no God or if there is he doesn't give a crap so I can live however I want

Fanatic moralism:
- ask why me?
- I must have done something wrong so try and be a better person

Most people are one of the two, some go back and forth between them

When we ask why?
- we need to learn to live without an answer and to embrace living without
- that shows whether we love God just for what He does for us or for who He is

Can I do that?

It's a hard faith
a cruel mountain pass
we cross hoping
but with no promise of
greener patures the other
side

It's a hard word
this disjointed syllable
we invoke hoping
that somewhere it will
be heard and
answered

It's a hard God
a wild animal who
asks for love and
admiration with the
promise of nothing in
return

I am selfish. So, so selfish. And I am afraid I will continue to be for some time yet. My dependence has never been on you. You have never defined me. I have depended on my friends, my work, my hobbies, even my beliefs and ideologies to define me but never you.

It made me feel good to hear your voice, to pray in tongues, to get guidance, words, pictures, etc. I know your spirit was in me and I don't think I was acting out of pride but maybe it was just a way to feel good about myself. And wasn't I often jealous of others' gifts?

It's true that my reaction at first was - have I not done enough? (moralism) But then it shifted to - because this is happening God must not care. I still firmly believe that when I was first diagnosed I was not doing anything wrong - there was nothing more I could have done to please God. I was exactly where he told me to be, doing His will as best I knew how. So the whole moralism thing didn't last very long.

And now I've been so cynical, believing that you're a malicious tyrant who inflicts suffering for the hell of it, or just not caring.

Anesthesia
I like the feeling
of going under
thick white liquid
capable hands push the syringec
ount backwards
10... 9...
veins warm, muscles dissolve
And quick
merciful sleep
too quickly over

Sunday, February 22, 2009

Spiritual dirt

This is a Red course stream of emails

Evan Peters said in part:
 I’m sure many share this perspective but specifically in recent years I have become fascinated with the examples of new life springing from death that I see all over creation (dirt is essentially a bunch of dead stuff, and from it comes nearly everything we need to live). These help remind me of my place in the world, both as someone growing out of things past (ie. people, ideas that have gone before me) and as someone who will contribute to lives to come, but most importantly as a child of God whose life is centered on Jesus’ death and resurrection.

Kris MacQueen said:
Evan, I LOVE the dirt metaphor. We are growing out of raw, organic material that is left behind by those who have gone before. 

I feel like the soil of our present culture is in pretty bad shape. Many of the nutrients have been taken out of the earth, and like the physical world we live in, there's a whole lot of synthetic materials trying to make up the balance, but with disastrous consequences. Part of the "good news" that the gospel has only recently become to me is that there is rich, well tended soil that we can root ourselves in. As a people with very little sense of history, the rich (though occasionally soiled and tarnished) legacy of the Church fills the void left by our sometimes plastic, synthetic culture.


I replied:

Deep connections with the past are wonderful But remember our Lord Himself made deep connections with His past. Son of David according to the flesh. Ancient of days according to the Spirit.

He choose to reveal Himself in a powerful historical context with a rich full spiritual vocabulary already in place. And He choose to reveal Himself through out history to individuals in key places. People like Moses who wore the veil, David who made the Psalms and so on.

And further more, this history is not over. I read in the prophesy of Revelation that there are two women in the future story. A whore of great wealth and power who is thrown down, and a bride of Messiah who is lifted up. We get to decide which woman we are part of.

The Bible is full of the story of Jesus acting through out history. It is indeed HIS story. And the future holds HER story. I cannot read my favorite prophet, Jeremiah and not see that word, read about Moses and the veil, read about the bride of Messiah, without realizing that it is the same story. And it all started in the garden when God looked at Adam alone and said 'it is not good'. Of course it is not good! HIS story is incomplete without HER story. 

And as for plastic synthetic culture, I have to both agree and plead guilty. For those who don't know me I am the VFX pipeline architect for a movie special effects company. And there is nothing quite so synthetic and plastic as CGI movies. Building the technology that makes that stuff possible is what I am doing for a living at the moment. Chatting with Kris this morning after worship we both expressed our individual desire to turn more of our talents to making things for the Kingdom of God. 

I would far sooner put my energy into worship in the desert with even just a small chance to inspire God's people than to make another Dragonball. You will see that movie come out in a month or so. Technically it is amazing stuff. Spiritually, well not so good. The problem is we cannot build a successful movie company around the next Narnia. And actually even movies like that are awarded by bids and contracts with a lot of studios competing. So in the end the worship expression in my desert might have to stick with music, which I love. And possibly some live action movies.

Just in closing, there is a name for the people of Israel that the rabbis gave them. It was a derogatory put down similar to the original meaning of Christian, which meant 'little Christs' (Andy preached on it this morning, wow connections). The term for a Jew living in the land is Am Ha Aretz. But today to be an Am Ha Aretz in Israel is a good thing. This term has been turned around as well. Now it means someone who sticks to it, who does not leave. No hardship can drive them out. Am Ha Aretz literally means dirt people.

Remembering beginnings

I posted this in the Red course too.

I remember so many deep connections. I remember at the age of 8 listening to a sermon and arguing with the pastor in my spirit. That is not what scripture says!!! I can remember the sermon, but this is supposed to be short so... And I can remember in that same service something else that happened that day for the first time. Something that has repeated itself to my surprise and delight many times.

I remember sitting in the balcony, hearing the choir and the congregation below, beside and behind me. I was right beside the front rail. And as I sang to the Lord in my spirit, I left my body and flew around the room in extacy worshiping of my God. In later years this would mature into several other kinds of worship experiences, I have seen Jacob's ladder, chariots of fire, and hosts of angels in these transcendent moments. Always they have surprised me. I cannot 'do it', to make these moments happen. But when my heart is in the right place then God visits me and takes me places I cannot describe.

And with this also has come a deep commitment to my Lord Jesus the Christ. Adonal Yeshuah HaMachiach in Hebrew. I am commited to Him and to His expression. I am committed to His word, His law, His ways and His teaching exactly as He gave it. When He said not one Jot or tittle shall be removed from Torah till all is fulfilled, I take it to mean just that. And He has not said all is fulfilled. Indeed He said He is coming back because there is more to do. Prepare The Way for the Lord!

Some people over the years have suggested that it is better to be humble than to be right. The problem with that is by humble they ask us to bow down. But bowing down to a lie is not humility. It is slavery. 

Let each person decide for them self what to do about a feast day or a holiday. Honor and love God. Express yourself and express the word of God. We are made for each other. Bless one another with your best blessing, your deepest wealth of spirit, your most humble profound wisdom. And give it in worship to our God. Give only your best. This is my cry.

About Me

Winnipeg, Manitoba, Canada
Messianic Jewish adherant Software architect music enthusiast