tag:blogger.com,1999:blog-79911169693054345712024-02-08T21:32:28.335+06:00Programming - A synonym of Passionprogrammer.in.paradisehttp://www.blogger.com/profile/09333947381283175026noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-7991116969305434571.post-50643634852369373652015-09-24T11:53:00.003+06:002015-09-24T11:53:58.859+06:00Immediately-Invoked Function Expression : what and why?<div dir="ltr" style="text-align: left;" trbidi="on">
I remember I was confused by the syntax of Immediately-Invoked Function Expression in my early days with JavaScript. I'll follow DRY principle in this blog post and shall point to the articles that I found most helpful when I learned this.<br />
<br />
The definitive explanation with very good examples can be found in Ben Alman's <a href="http://benalman.com/news/2010/11/immediately-invoked-function-expression/" target="_blank">blog post</a>. He actually coined the term IIFE which was widely adopted later in JavaScript community.<br />
<br />
Why and when to use IIFE? 2 cases are recurring:<br />
<b>1) create private namespace:</b> We can create private functions and properties and can expose only those members intended to be public. This helps us not to pollute global namespace. Vivin Paliath explained this really well on <a href="http://stackoverflow.com/a/2421949" target="_blank">stackoverflow</a>.<br />
<br />
<b>2) resolve global variable conflict:</b> Josh Mock gave a <a href="http://tech.myemma.com/iifes-javascript-control-variable-scope/" target="_blank">good example</a> of this.</div>
programmer.in.paradisehttp://www.blogger.com/profile/09333947381283175026noreply@blogger.com0tag:blogger.com,1999:blog-7991116969305434571.post-24414244914804725162015-09-21T11:14:00.000+06:002015-09-21T12:33:28.349+06:00Skills of a full stack developer<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
I had the following questions:</div>
<div style="text-align: justify;">
</div>
<ol>
<li>What is the standard definition or scope of full stack developer?</li>
<li>What does that 'full stack' look like actually?</li>
<li>Why do employers seek full stack developer instead of developers specializing in particular aspects?</li>
<li>What are the skills a full stack developer bring to the table?</li>
<li>How to become a full stack developer? Is there any road map?</li>
</ol>
<br />
<div style="text-align: justify;">
So I googled and read blog posts and articles. Here's my findings:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<b>1. What is the standard definition or scope of full stack developer?</b></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
There is no acceptable definition yet. Some people have tried to define it in a logical way; some called it <a href="https://blog.growth.supply/the-full-stack-developer-is-a-myth-4e3fb9c25867" target="_blank">meaningless</a> with valid arguments. Facebook engineer Carlos Bueno <a href="https://www.facebook.com/notes/facebook-engineering/the-full-stack-part-i/461505383919" target="_blank">defined</a> full stack developer as a generalist with a broad range of skills. Mike Loukides <a href="http://radar.oreilly.com/2014/04/full-stack-developers.html" target="_blank">echoed</a> the same idea - "Full-stack development is about exposing yourself to a broad range of ideas". The general impression that I got after reading several other articles is that it's a term being used to mean engineers or developers who is capable of working in any layer of the whole stack (usually web stack).</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<b>2. What does that 'full stack' look like actually?</b></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The first bottleneck of defining a full stack developer is coming up with a good idea of the stack itself. Scott Hadfield <a href="https://blog.growth.supply/the-full-stack-developer-is-a-myth-4e3fb9c25867" target="_blank">presented</a> a non-exhaustive list of layers that contains from hardware, OS, hosting, scaling to frameworks, front-end dev, security, business requirements. Edward Chung <a href="http://edward-designer.com/web/full-stack-web-developer" target="_blank">gave</a> a list of roles/jobs needed to build a web application, ranging from web designer to web analyst, quality assurance tester.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Whenever we hear 'full stack', we usually think of LAMP, WAMP, or MEAN stack. What is obvious now is that these acronym-style stacks are just the tip of the iceberg or we can say the beginning of a long yet fun and rewarding journey.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<b>3. Why do employers seek full stack developer instead of developers specializing in particular aspects?</b></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The main reason for hiring 'jack of all trades' is speed and the economic benefit that follows. When a company wants to build a prototype or a MVP (Minimum Viable Product), a full stack developer is very handy. Because (s)he can understand and work in all layers of the application. This essentially eliminates the overhead of communication, for instance, between UI designer, front end developer, back end developer, database developer and database administrator, DevOps engineer. In an Agile environment, a full stack developer can focus on a complete end-to-end feature.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<b>4. What are the skills a full stack developer bring to the table?</b></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Jack of all trades, master of a few. In my opinion, that's a reasonable expectation. We no longer can afford to remain in a silo and to become a true master of one thing but almost ignorant of others. A full stack developer is able to grasp the big picture - the whole stack - and working across the layers and whenever help is needed, (s)he is able to communicate the problem effectively to an expert in the team. The 'value proposition' of full stack developer is versatility.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<b>5. How to become a full stack developer? Is there any road map?</b></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
This is subjective. The answer also depends on the background (web designer vs. web developer) of an aspiring full stack developer. The following is the start of one of many possible road maps:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
JavaScript-based platforms and frameworks are extremely in demand now. So this road map assumes that we want to be proficient in JavaScript-based full stack.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
</div>
<ol>
<li>Decide on a project idea that you are very motivated to see coming into life. Write down the detailed requirements. Create 'user stories'. Go through the requirements again and again so that you have a good idea of what you're going to get. If you don't have any idea, just google for project idea.</li>
<li>Learn the basics of language first. As you work more and more in that language, you will learn details about the different features the language provides. It is not a good idea to target being a master in the first step. Just get comfortable using the language.</li>
<li>Pick a popular front end framework or library. I wasted a lot of time trying to figure out THE ONE. Like all programming languages, frameworks and libraries have strengths and weaknesses. AngularJS is a very popular and established framework now. Let's start with this. The experience gained while working with one framework/library will definitely help you pick another one very fast. Do a few tutorials of AngularJS. Then implement the client-side functionalities of your project.</li>
<li>Pick a back end framework or library. Node.js is the most popular JavaScritp based platform. Pick a popular Node.js-based framework or library. Following MEAN stack, you can choose Express framework. (By the way, the number of JavaScript-based libraries and frameworks will soon outnumber the population of the world. So don't spend too much time to choose the 'best' like I did.) Do a few tutorials of Express. Then implement the server-side functionalities of your project. It's okay if data is hard-coded for now. Expose your server-side capabilities as APIs. Modify client-side to consume those APIs.</li>
<li>Pick a database. A full stack developer should be very knowledgeable about the trade-offs of relational vs non-relational (NoSQL) databases and must know when to use which. For now, just pick MongoDB. Learn the basics, design your data collections and attributes. Do a few tutorials of Mongoose and know how what it is useful for. Finally implement the integration of your server-side code with DB. You should be careful about how you keep the DB interaction logic and business logic separate in your code base.</li>
<li>Now it's time for deployment. You can use cloud infrastructure provider. In that case, learn about docker, do a few tutorials and write dockerfile for your client, server and DB containers. You can use docker-compose (successor of Fig). Alternatively, you can use PaaS, for example, Heroku or Pivotal (Cloud Foundry). Learn how to use them.</li>
<li>Now start broadening your knowledge about trade-offs involved in design decisions. In addition to that, increase your familiarity with different available libraries and frameworks. Let's start with front end. What are the other popular alternatives? Pick one by one. Do a few tutorials. Re-implement your client-side with that library or framework. What kind of client-side needs is this suitable for? Do the same things for back end.</li>
<li>Regarding databases, know about different data models of NoSQL databases (key-value, column, document, graph) and the trade-offs (performance, scalability, flexibility, complexity). Which one will be the most appropriate for your project when you have millions of hits per hour? Moreover, in which cases relational databases are the most appropriate ones?</li>
<li>Eventually the back end can be a distributed application communicating through messaging. How can you decompose your back end application into small independent applications so that you can scale in a more refined manner? This is where polyglot programmers come in handy. For instance, you can implement a CPU-intensive part of your distributed application in Go.</li>
</ol>
<br />
<div style="text-align: justify;">
I would appreciate your suggestions regarding the possible road maps for being a full stack developer.</div>
</div>
programmer.in.paradisehttp://www.blogger.com/profile/09333947381283175026noreply@blogger.com8tag:blogger.com,1999:blog-7991116969305434571.post-8376122310560152922012-08-22T16:10:00.000+06:002012-08-22T16:10:41.899+06:00Tracking Time at Office<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
Before being a team lead, I used to work on a single task, in addition to the usual office chores. Now things have changed a lot. I find it hard to keep track of time during office hours. At the end of day, I wonder how much time I actually spent on my assigned task, how much time I worked with other teammates. I felt the need of a time tracking software.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
In my previous software firm, Structured Data Systems Ltd. - an offshore branch of AfriGIS, South Africa, employees were encouraged to track time by using a software named Klok. A free version is available. I have started using it.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
I intend to try out other related softwares later.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Here is the template I am using now:</div>
<div style="text-align: justify;">
<br />Office chores<br /> > Check office mail<br /> > Daily scrum meeting<br /> > General office meeting : occurs occasionally<br /> > Lunch<br /> > Refreshment : 2 times a day - at around 11 am and 5 pm.<br /> > Table Tennis : we play TT at office!<br /> </div>
<div style="text-align: justify;">
Team work<br /> > Check client issues at JIRA and update TRAC<br /> > Check teammates' yesterday's work at TRAC<br /> > Today's task assignment <br /> > Retrospective meeting: weekly event<br /> > Work with teammates: I frequently do this. Tracking time for every teammate will enable me to find a trend about with whom or on what task I do pair-programming for a given period of time.<br /> > Knowledge sharing session: I greatly encourage to do this immediately after lunch when everyone is relaxed. I am planning to practice this more vigorously.<br /> > Meeting with Product Development Manager (PDM): occurs everyday intermittently.</div>
<div style="text-align: justify;">
<br /></div>
</div>
Unknownnoreply@blogger.com0Dhaka, Bangladesh23.709921 90.40714323.4773095 90.091286000000011 23.942532500000002 90.723tag:blogger.com,1999:blog-7991116969305434571.post-56758948265522623752012-08-08T11:55:00.001+06:002012-08-08T13:01:13.035+06:00Checklist Before You Join a New Company<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
Sometimes I browse the job sites to find out companies for better opportunity. When a job circular seems good, many questions pop up in my mind. Often, I can manage someone familiar working there and I get to know about that particular company.<br />
<br />
I think it is a good idea to have a checklist for this. Here it goes!<br />
<br />
PROJECT:<br />
<br />
1) How many projects are currently going on?<br />
<br />
2) What is the average age of the projects?<br />
<br />
3) Which technologies does the company work with?<br />
<br />
4) How important is the project (for which recruitment is going on) to the company?<br />
<br />
5) What are the application domains of the ongoing projects?<br />
<br />
6) What is the average experience of engineers working there? I mean years of experience for most of the engineers.<br />
<br />
WORK CULTURE:<br />
<br />
1) How do you think the company provides a good learning opportunity for an engineer?<br />
<br />
2) Do you feel sportive at office? or it feels like a conventional office (everyone working at his desk, no adda, few brainstorming among colleagues)?<br />
<br />
3) How many hours do you "actually" need to work a day, on average? I mean, productive hour.<br />
<br />
4) How frequent is overtime?<br />
<br />
5) How frequent is working on weekend?<br />
<br />
6) Do you feel that your job is secure?<br />
<br />
7) How friendly is the relationship among the engineers?<br />
<br />
8) How cooperative is the relationship between engineers and management?<br />
<br />
9) What do you think a unique quality of the company that sets it apart from the other companies in the market?<br />
<br />
10) Do you follow any software development process? If yes, what is it?<br />
<br />
REMUNERATION:<br />
<br />
1) What is the salary range for a fresher?<br />
<br />
2) How many times in a year do your company give salary increment?<br />
<br />
3) What is the average percentage of increment?<br />
<br />
4) Is project bonus a regular phenomenon?<br />
<br />
5) What are the other benefits?</div>
</div>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-7991116969305434571.post-34541157476748379792011-07-26T16:37:00.003+06:002011-07-26T17:01:49.565+06:00snprintf is not a member of std<div style="text-align: justify;">I am working on an <a href="http://en.wikipedia.org/wiki/Xcode">Xcode</a> project that includes boost thread library through <a href="http://www.clintharris.net/2009/iphone-app-shared-libraries/">cross-project reference</a>. One step of setting up cross-project reference is to add value for <i>Header Search Paths</i> setting under <i>Build</i> tab (from project target's <i>Get Info</i> option). While doing so, I have checked the <i>Recursive</i> check-box.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">When the project is built, the following error occurs:</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><span class="Apple-style-span" style="font-family:'courier new';">/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.3.sdk/usr/include/c++/4.0.0/i686-apple-darwin9/bits/c++locale.h:72: error: 'snprintf' is not a member of 'std'</span></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Googling leads to <a href="http://boost.2283326.n4.nabble.com/Mac-Xcode-3-0-Boost-compile-issue-td2577706.html">a solution</a> - Uncheck the <i>Recursive</i> check-box.</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Xcode version I am working with is 3.1.4.</div>programmer.in.paradisehttp://www.blogger.com/profile/09333947381283175026noreply@blogger.com0tag:blogger.com,1999:blog-7991116969305434571.post-16843409018791101422011-07-15T12:20:00.004+06:002011-07-22T11:22:16.853+06:00How to build OpenSSL in Xcode<div style="text-align: justify;">I extensively googled for how to build OpenSSL library in Xcode for iOS. I found the following links most useful:<br /><br />* <a href="http://www.x2on.de/2010/07/13/tutorial-iphone-app-with-compiled-openssl-1-0-0a-library/">TUTORIAL: IPHONE APP WITH COMPILED OPENSSL 1.0.0A LIBRARY</a><br /><br />Describes how to use already built OpenSSL static library in an Xcode project, how to build static libraries of OpenSSL for different architectures (i386, armv6, armv7) from <a href="http://en.wikipedia.org/wiki/Apple_Terminal">terminal</a>, how to make universal fat library with lipo command.<br /><br />* <a href="http://www.x2on.de/2010/12/16/tutorial-script-for-building-openssl-for-ios-iphoneipad/">TUTORIAL: SCRIPT FOR BUILDING OPENSSL FOR IOS (IPHONE/IPAD)</a><br /><br />Script to build for both simulator and device.<br /><br />* <a href="http://atastypixel.com/blog/easy-inclusion-of-openssl-into-iphone-app-projects/">Easy inclusion of OpenSSL into iOS projects</a><br /><br />Points to the following two Xcode projects on github that hides all the 'black magic':<br /> 1. <a href="https://github.com/sjlombardo/openssl-xcode">Xcode project for OpenSSL by Stephen Lombardo</a><br /> 2. <a href="https://github.com/michaeltyson/openssl-xcode">Xcode project for OpenSSL by Michael Tyson</a><br /><br />Michael Tyson's project is easier as it simplifies Lombardo's project.<br /><br />Since our target is to use cross-project reference technique wherever possible due to its greater flexibility in building for different architectures(i386, armv6, armv7), I went for Xcode project approach and used <a href="https://github.com/michaeltyson/openssl-xcode">the one created by Michael Tyson</a>.<br /><br /><span style="font-weight: bold;">The procedure</span> is given below:<br /> 1. Download the OpenSSL source code directly from http://www.openssl.org/source/<br /> 2. Clone the openssl-xcode git repo to make a local copy<br /> 3. Put the downloaded OpenSSL source tar.gz into the same folder as openssl.xcodeproj.<br /> 4. The extracted OpenSSL distribution can also be placed in a folder called 'openssl' within the same folder as openssl.xcodeproj, or just extracted within the same folder as openssl.xcodeproj.<br /> 5. Then open openssl.xcodeproj in XCode and initiate a build<br /><br /><span style="font-weight: bold;">A possible problem:</span><br />In the Xcode project window, under <span style="font-style: italic;">Products</span> directory, there is only libcrypto.a static library. As far as I know, OpenSSL build is supposed to produce two static libraries - libcrypto.a and libssl.a. However, I found libssl.a within the same folder as xcodeproj file. I sent a mail to Stephen Lombardo, original Xcode project creator for OpenSSL, still did not get any reply to the query - why libssl.a is not present in the <span style="font-style: italic;">Products</span> folder of Xcode window.<br /><br /><span style="font-weight: bold;">Update #1:</span><br />The problem I guessed might happen actually happened when I tried to use the intended module from a test project. A good number of link errors related to SSL were produced. Googling with the first link error phrase <span style="font-style: italic;">SSL_CTX_free</span> confirmed that <span style="font-family: courier new;">libssl</span> were not linked properly. I did not know how to add an additional library to <span style="font-style: italic;">Products</span> folder (under <span style="font-style: italic;">Groups and Files</span> pane in Xcode project window) so that it can be linked properly. Adding <span style="font-family: courier new;">libssl.a</span> file to <span style="font-style: italic;">Products</span> folder in a straightforward manner did not help remove those link errors.<br /><br />While trying out in an adhoc manner, I finally came up with the following procedure that could eliminate those SSL-related link errors:<br /><br /><span style="font-weight: bold;">Add libssl.a to the </span><span style="font-style: italic; font-weight: bold;">Products</span><span style="font-weight: bold;"> folder under </span><span style="font-style: italic; font-weight: bold;">Groups and Files</span><span style="font-weight: bold;"> pane in </span><span style="font-family: courier new; font-weight: bold;">openssl</span><span style="font-weight: bold;"> project's window:</span><br /><br />Step 1: Add New Target <span style="font-family: courier new;">ssl</span>:<br /><br />Right click on <span style="font-style: italic;">Targets</span> under <span style="font-style: italic;">Groups and Files</span> pane.<br />Select <span style="font-style: italic;">Add -> New Target...</span><br />A dialog with title "New Target" will appear. On the left, under <span style="font-style: italic;">iPhone OS</span> category, select <span style="font-style: italic;">Cocoa Touch</span>. Then on the right, select <span style="font-style: italic;">Static Library</span>.<br />Click <span style="font-style: italic;">Next</span> button. Write <span style="font-family: courier new;">ssl</span> for <span style="font-style: italic;">Target Name</span>. <span style="font-family: courier new;">openssl</span> should be selected for <span style="font-style: italic;">Add To Project</span>.<br />Click <span style="font-style: italic;">Finish</span>.<br /><br />Step 2: Enter info about target <span style="font-family: courier new;">ssl</span>:<br /><br />A new window titled <span style="font-style: italic;">Target "ssl" Info</span> will appear from the previous step.<br /><br />We need to add <span style="font-family: courier new;">crypto</span> as a dependency of <span style="font-family: courier new;">ssl</span>. Under <span style="font-style: italic;">General</span> tab, Between <span style="font-style: italic;">Direct Dependencies</span> and <span style="font-style: italic;">Linked Libraries</span>, click <span style="font-weight: bold;">+</span> and select <span style="font-family: courier new;">crypto</span>, then click <span style="font-style: italic;">Add Target</span>.<br /><br />Select <span style="font-style: italic;">Build</span> tab. Type <span style="font-family: courier new;">search</span> in the search box.<br />Under <span style="font-style: italic;">Search Paths</span> category, for <span style="font-style: italic;">User Header Search Paths</span> key, add value <span style="font-family: courier new;">$(openssl_SRC)</span> as path, set <span style="font-style: italic;">Recursive</span> checkbox. <span style="font-family: courier new;">openssl_SRC</span> is an Xcode <span style="font-style: italic;">Source Tree</span> variable defined from Xcode Preferences. It refers to the directory in which <span style="font-family: courier new;">openssl.xcodeproj</span> file is.<br />For <span style="font-style: italic;">Header Search Paths</span> key, add value <span style="font-family: courier new;">$(openssl_SRC)/openssl/include</span><br />Close the window.<br /><br />Step 3: Link<br />Under <span style="font-style: italic;">Groups and Files</span> pane, drag <span style="font-family: courier new;">libssl.a</span> from <span style="font-style: italic;">Products</span> folder to <span style="font-style: italic;">Targets -> ssl -> Link Binary with Libraries</span> folder.<br /><br />Now the other projects that referred to openssl project with the help of cross-project reference mechanism should have both libcrypto.a and libssl.a static libraries when <span style="font-family: courier new;">openssl.xcodeproj</span> is expanded in client project's Xcode window.<br /><br /><span style="font-weight: bold;">Additional necessary steps for client projects:</span><br />Now that a new static library <span style="font-family: courier new;">libssl.a</span> has been added to openssl project, client projects must know about it. If <span style="font-family: courier new;">libssl.a</span> is added to openssl project before any client project refers to openssl project via cross-project reference mechanism, this is not necessary.<br /><br />Let's assume <span style="font-style: italic;">openSslClient</span> project is using openssl project.<br /><br />Right click on <span style="font-style: italic;">openSslClient</span> under <span style="font-style: italic;">Targets</span>, select <span style="font-style: italic;">Get Info</span>. A new window titled <span style="font-style: italic;">Target "openSslClient " info</span> will appear.<br /><br />Under <span style="font-style: italic;">General</span> tab, add <span style="font-family: courier new;">ssl</span> to <span style="font-style: italic;">Direct Dependencies</span>.<br /><br />Under <span style="font-style: italic;">Build</span> tab, <span style="font-style: italic;">User Header Search Paths</span> and <span style="font-style: italic;">Header Search Paths</span> should have appropriate values for openssl as it was done earlier for <span style="font-family: courier new;">libcrypto.a</span>. <span style="font-style: italic;">openssl.xcodeproj</span> was added to <span style="font-style: italic;">openSslClient</span> project through cross-project reference, following <a href="http://www.clintharris.net/2009/iphone-app-shared-libraries/">an excellent article</a> by Clint Harris.<br /><br />Close window.<br /><br />Under <span style="font-style: italic;">Groups and Files</span> pane, expand <span style="font-family: courier new;">openssl.xcodeproj</span> and drag <span style="font-family: courier new;">libssl.a</span> from there to <span style="font-style: italic;">Targets -> openSslClient -> Link Binary with Libraries</span> folder.<br /><br />Update #2:<br />Stephen Lombardo replied to my mail. He suggested adding a second target for ssl. I have already done this :-)<br /></div>Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-7991116969305434571.post-22632992916600679882011-07-13T17:58:00.005+06:002011-07-15T12:28:21.864+06:00How to build c-ares library in Xcode<div style="text-align: justify;">- Download the <a href="http://c-ares.haxx.se/">latest version of c-ares library</a> on a Mac and unzip it.<br />- Open the terminal and go to the source file directory.<br />- Execute <span style="font-size:130%;"><span style="font-family:courier new;">./configure</span></span> and it will create <span style="font-size:130%;"><span style="font-family:courier new;">ares_config.h</span></span> file.<br /><br />- Now open a new project in Xcode. I created a <span style="font-style: italic;">Library</span> project for<span style="font-style: italic;"> iPhone OS</span> category and named it 'cares'.<br />- Right click on '<span style="font-style: italic;">Classes</span>' and select <span style="font-style: italic;">Add </span>-> <span style="font-style: italic;">Existing Files</span>. A file dialog box will appear. Select and add the source file directory. The source codes will be added to the project.<br />- Right click on the project and select '<span style="font-style: italic;">Get Info</span>'. Under '<span style="font-style: italic;">Build</span>' tab, write 'flags' in the search box. You will see an entry named "<span style="font-style: italic;">Other C Flags</span>". Add value <span style="font-style: italic;">-DHAVE_CONFIG_H</span> for it.<br /><br />Now c-ares library should be built in Xcode without any error.<br /></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7991116969305434571.post-77491578001494781492011-05-26T16:24:00.010+06:002011-05-26T18:05:53.474+06:00Checklist while porting from C++ to JavaI have been working in a project which involves porting the code base from C++ to Java (to be precise, J2ME). The code base is large and we have been under severe pressure to get it working for the first release. What we have been doing is basically copy-paste the code of a class from C++ to Java, then removing errors, adjusting syntax and the like. What we often overlooked is the semantic differences between these two languages and hard-to-find bugs crept in insidiously.<br /><br />So I think a checklist would be handy for this:<br /><br /><span style="font-weight: bold;">(1) C++ copy constructor and overloaded assignment operator:</span><br /><br /><span style="font-size:100%;"><span style="font-family:courier new;">ClassA obj1;<br />// ...<br /></span><span style="font-family:courier new;">// code modifying obj1</span><span style="font-family:courier new;"><br /></span></span><span style="font-size:100%;"><span style="font-family:courier new;">// ...<br /><br /></span></span><span style="font-size:100%;"><span style="font-family:courier new;">ClassA obj2;</span><span style="font-family:courier new;"><br />obj2 = obj1; // overloaded assignment operator gets called</span><span style="font-family:courier new;"><br /><br />// or</span><span style="font-family:courier new;"><br />ClassA obj2 = obj1; // copy constructor gets called</span></span><br /><br />If ClassA defines a copy constructor, then obj2 will be initialized to data with same value but with different allocated memory (deep copy). So subsequent changes made to obj2 does not affect obj1 and vice versa.<br /><br />Now while porting, this statement (obj2 = obj1) does not generate compile error in Java and reference of obj1 is copied to obj2. So both obj1 and obj2 refer to, in fact, the same instance. We did not notice it and since changes in obj2 or obj1 affected the same object/instance, we were in trouble as it was not meant in the original C++ code.<br /><br />The right way of doing this is to add an overloaded constructor of ClassA.<br /><br /><span style="font-size:100%;"><span style="font-family:courier new;">public ClassA(ClassA anInstance) {</span><span style="font-family:courier new;"><br />// copy data from the given argument.</span><span style="font-family:courier new;"><br />// deep copy if needed.</span><span style="font-family:courier new;"><br />}</span><br /></span><br />Instead of<br /><br /><span style="font-family:courier new;">obj2 = obj1</span>;<br /><br />change this in the ported code:<br /><br /><span style="font-family:courier new;">obj2 = new ClassA(obj1);</span><br /><br /><span style="font-weight: bold;">(2) C++ overloaded == operator:</span><br /><br /><span style="font-size:100%;"><span style="font-family:courier new;">if (obj2 == obj1) {</span><br /><span style="font-family:courier new;"> // ....</span><br /><span style="font-family:courier new;">}</span></span><br /><br />This statement also does not generate compile error. In C++, if ClassA overloads == operator, then the overloaded == method gets called. But in Java, this statement simply compares references of obj2 and obj1 which is not intended at all. This statement should be replaced by<br /><br /><span style="font-family:courier new;">obj2.equals(obj1) </span><br /><br />and Object::equals() must be overridden in ClassA.<br /><br /><span style="font-weight: bold;">(3) C++ pointer/reference used to receive output from a method:</span><br /><br />I do not consider it a good practice to pass pointer to a function in order to receive output. Example:<br /><pre>bool getWidthHeight(int& width, int& height)<br />{<br /> width = this->width;<br /> height = this->height;<br /> return true;<br />}</pre><br />Return value indicates success or failure. This is pervasive in the code base I ported. So how do I have to simulate this? In Java, I defined a class like this:<br /><pre>public class pInt {<br /> public int value;<br /> public pInt(int value) {<br /> this.value = value;<br /> }<br />}<br /></pre><br />So I ported that method like this in Java:<br /><pre>boolean getWidthHeight(pInt width, pInt height) {<br /> width.value = this.width;<br /> height.value = this.height;<br /> return true;<br />}</pre><br />This had to be done for every built-in or custom type for which a pointer was used to receive output. This is tedious and for mobile platform is not acceptable. But for the first release, I think, nobody will mind this workaround.<br /><br /><span style="font-weight: bold;">(4) C++ conditional compilation</span>:<pre>#ifdef CONDITION_1<br /> // ....<br />#else<br /> // ....<br />#endif</pre><br />I maintained a separate class, say Configurations, for these conditions and set value true or false for them. Then the ported code looked like:<pre>if (Configurations.CONDITION_1 == true) {<br /> // ........<br />} else {<br /> // ....<br />}</pre>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7991116969305434571.post-34045062192293252192011-01-17T15:39:00.003+06:002011-01-17T16:07:10.523+06:00Non-blocking Network I/O and Timeout in BlackBerry API<div style="text-align: justify;">Currently I am working on porting a C++ project to BlackBerry JDE 5.0. In the C++ implementation of the project, I have noticed use of select() function to enforce timeout property in C++ socket programming. I had to find non-blocking network I/O API in BlackBerry JDE 5.0 documentation but to no avail. As <a href="http://supportforums.blackberry.com/t5/user/viewprofilepage/user-id/75315">klyubin</a> <a href="http://supportforums.blackberry.com/t5/Java-Development/another-socket-problem-socket-is-not-receiving-although-it-is/m-p/439394#M86743">pointed out</a>, no non-blocking I/O API is present on BlackBerry. He suggested two solutions: (1) setting a read/write timeout on the connection (which is not supported on some old platforms) and (2) periodically checking some timeout value from another thread (e.g., daemon thread, Timer, event dispatcher) and disconnect once the timeout expires.<br /><br />The first solution seemed faster to integrate. So I searched and found the following:<br /><br />For UDP connection, use DatagramConnectionBase.<br /><br /><div style="text-align: left; font-family: courier new;"><span style="font-size:85%;"><span style="font-size:100%;">DatagramConnectionBase connection = (DatagramConnectionBase) Connector.open(connectionString, mode, true); // 3rd argument : timeout is enabled<br />connection.setTimeout(10000); // 10 seconds</span><br /></span></div><br />For TCP connection, use SocketConnectionEnhanced as <a href="http://supportforums.blackberry.com/t5/Java-Development/Connection-timeout-different-with-socket/m-p/22208#M843">pointed out</a> by <a href="http://supportforums.blackberry.com/t5/user/viewprofilepage/user-id/12325">Mark Sohm</a>.<br /><br />For TCP connection through BES (BlackBerry Enterprise Server), the following BlackBerry Knowledge Base article is useful:<br /><a href="http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/How_To_-_Control_the_connection_timeout_for_TCP_connections_through_BlackBerry_Mobile_Data_System_Connection_Service.html?nodeid=1235131&vernum=0">How To - Control the connection timeout for TCP connections through the BlackBerry MDS Connection Service</a><br /><br /></div>programmer.in.paradisehttp://www.blogger.com/profile/09333947381283175026noreply@blogger.com0tag:blogger.com,1999:blog-7991116969305434571.post-43059330346360579682010-08-31T18:15:00.004+06:002010-08-31T18:55:41.941+06:00Custom accessory view of table view cell : accessoryButtonTappedForRowWithIndexPath method is not calledIn my attempt to implement a custom accessory view for table view cell, I faced a weird problem. While everything in my code looked okay, the <span style="font-style: italic;">accessoryButtonTappedForRowWithIndexPath</span> method was not being invoked when I tapped the custom accessory button.<br /><br />Sample code <a href="https://developer.apple.com/iphone/library/samplecode/Accessory/Introduction/Intro.html"><span style="font-weight: bold;">Accessory</span></a> provided by Apple helped me sort out the problem. Here the clue is that the custom accessory view must have a custom button which will be wired to a predetermined target and action.<br /><br />In the method <span style="font-style: italic;">cellForRowAtIndexPath</span>:<br /><br /> <span style="font-size:85%;"><span style="font-family: courier new;">UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];</span><br /><span style="font-family: courier new;"> CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);</span><br /></span><span style="font-size:85%;"><span style="font-family: courier new;"> // match the button's size with the image size</span></span><br /><span style="font-size:85%;"><span style="font-family: courier new;"> button.frame = frame;</span><br /><span style="font-family: courier new;">[button setBackgroundImage:image forState:UIControlStateNormal];</span><br /><br /><br /><span style="font-family: courier new;">// set the button's target to this table view controller so<br />// we can interpret touch events and map that to a NSIndexSet</span><br /><span style="font-family: courier new;">[button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];<br /><br /></span><span style="font-family: courier new;"> cell.accessoryView = button;</span></span><br /><br /><br /><span style="font-family: courier new;font-size:85%;" >- (void)checkButtonTapped:(id)sender event:(id)event<br />{<br /> NSSet *touches = [event allTouches];<br /> UITouch *touch = [touches anyObject];<br /> CGPoint currentTouchPosition = [touch locationInView:self.tableView];<br /> NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];<br /> if (indexPath != nil)<br /> {<br /> [self tableView: self.tableView accessoryButtonTappedForRowWithIndexPath: indexPath];<br /> }<br />}</span><br /><br />Reference:<br /><a href="https://developer.apple.com/iphone/library/samplecode/Accessory/Listings/MyTableViewController_m.html#//apple_ref/doc/uid/DTS40008066-MyTableViewController_m-DontLinkElementID_6">Sample code of custom accessory view from Apple</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7991116969305434571.post-54433204069459544392010-08-30T11:35:00.004+06:002010-08-30T11:49:52.859+06:00Warning : declaration of 'variableName' hides instance variable<div style="text-align: justify;">The large number of warnings of the following kind seem to me really annoying, though I can realize the need of it.<br /><br /><span style="font-weight: bold;">declaration of 'variableName' hides instance variable</span><br /><br />I googled for a nice work-around to avoid this warning but could not find any. Many have suggested to use underscore prefix for instance variables but some pointed out that underscore prefix notation has been reserved by Apple. The others suggested to use the convention of using the/a/an before the variable name but it seems to me quite distasteful!<br /><br />Helpless, I opted for the latter solution :-(<br /><br /><span style="font-style: italic;">References:</span><br />1. <a href="http://stackoverflow.com/questions/2541716/objective-c-convention-to-prevent-local-declaration-hides-instance-variable-war">Objective-C convention to prevent “local declaration hides instance variable” warning</a><br />2. <a href="http://www.cocoabuilder.com/archive/cocoa/233929-suppressing-variable-hiding-warning-in-xcode.html">Suppressing variable hiding warning in Xcode</a><br />3. <a href="http://stackoverflow.com/questions/1258260">Parameters hide instance variables in Objective-C</a><br /></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7991116969305434571.post-25430754763503481682009-12-16T16:36:00.009+07:002009-12-16T17:40:27.792+07:00Checking for NULL pointer before deleting or calling free()<div style="text-align: justify;">Today after reading two posts (references given at the end) from <a href="http://stackoverflow.com/">Stack Overflow</a> I have got a better understanding of how dynamically allocated memory should be freed and why in that way.<br /><br />Earlier I knew only that pointer should be checked against NULL before freeing memory, otherwise catastrophic disaster may occur because it may happen that an already freed memory is being freed again. So I always put it like:<br /><br /><span style="font-family:courier new;">if (pointer == NULL) {</span><br /><span style="font-family:courier new;"> free(pointer); // or "delete pointer;" in C++</span><br /><span style="font-family:courier new;">}</span><br /><br />Later while working with files in C, I came to realize that freeing memory in this fashion does not make the pointer NULL. So <a href="http://en.wikipedia.org/wiki/Dangling_pointer">dangling pointer</a> surfaces in this context. I added another line:<br /><br /><span style="font-family:courier new;">pointer = NULL;</span><br /><br />However, freeing a NULL pointer is not a problem at all now because according to ANSI standard, free() function does nothing when the passed pointer is NULL.<br /><br />For the sake of being cautious and avert non-standard compilers from causing havoc to your program, you may check for NULL pointer. Otherwise, it all boils down to only the following 2 lines:<br /><br /><span style="font-family:courier new;">delete pointer;</span><br /><span style="font-family:courier new;">pointer = NULL;</span><br /><br /><br />References:<br /><br />(1) <a href="http://stackoverflow.com/questions/1912325/checking-for-null-before-calling-free">checking for NULL before calling free</a><br />(2) <a href="http://stackoverflow.com/questions/615355/is-there-any-reason-to-check-for-a-null-pointer-before-deleting">Is there any reason to check for a NULL pointer before deleting?</a><br /><br /></div>programmer.in.paradisehttp://www.blogger.com/profile/09333947381283175026noreply@blogger.com0tag:blogger.com,1999:blog-7991116969305434571.post-85475127083195494292009-12-15T13:23:00.002+07:002009-12-15T14:05:53.980+07:00BlackBerry application facing HTTP connection problem on simulator<div style="text-align: justify;">Before testing an application that uses HTTP connection on BlackBerry simulator, I often forget to enable Mobile Data Service (MDS) with the simulator and I find my application not working as expected.<br /><br />So if you encounter problem with your application failing to establish HTTP connection, check your intended simulator's MDS setting.<br /><br />To enable MDS setting,<br /><br />1. From JDE, go to <span style="font-style: italic;">Edit -> Preferences </span><br />2. Select <span style="font-style: italic;">Simulator</span> tab<br />3. Select <span style="font-style: italic;">General</span> tab under <span style="font-style: italic;">Simulator</span> tab<br />4. Check <span style="font-style: italic;">"Launch Mobile Data Service (MDS) with Simulator"</span><br /></div>programmer.in.paradisehttp://www.blogger.com/profile/09333947381283175026noreply@blogger.com0tag:blogger.com,1999:blog-7991116969305434571.post-32142927837032916732009-12-08T13:46:00.009+07:002009-12-08T14:43:59.977+07:00How to clean or reset BlackBerry simulator<div style="text-align: justify;">For a veteran BlackBerry developer, it is not unusual to get his BlackBerry simulator crammed with many icons of applications he developed over the years. At one point, when he needs to scroll deep down the screen to find his intended application icon, it becomes really annoying. He then wants to remove application icons from the simulator.<br /><br />Another kind of need may arise in case of an application which requires the simulator reset its file system each time the simulator is launched.<br /><br />I have two versions of the same application with same application icon installed on simulator. I wanted to clear everything up and to test one particular version. But I did not know how to do it. I then googled and found the following solutions.<br /><br /><a href="http://supportforums.blackberry.com/t5/Java-Development/cleaning-simulators/m-p/306834">Solution #1</a>: In JDE, go to <span style="font-style: italic;">File -> Erase simulator file</span><br /><br />Deletes the <span style="font-style: italic;">dmp</span> files from the simulator directory but does not remove the application icons.<br /><br /><a href="http://www.blackberryforums.com/developer-forum/110403-clean-simulators.html">Solution #2</a>: From command line, run <span style="font-style: italic;">clean.bat</span> located at simulator sub-directory under JDE installation directory such as <span style="font-style: italic;">C:\Program Files\Research In Motion\BlackBerry JDE 4.3.0\simulator</span><br /><br />Deletes your applications' files and <span style="font-style: italic;">dmp</span> files from the simulator directory. So the icons are removed!<br /><br /><a href="http://supportforums.blackberry.com/t5/Java-Development/simulator-reset-clean/m-p/49534;jsessionid=0856C2409F646660495210B5ADF374D3">Solution #3</a>: Delete the following files located at the simulator directory such as <span style="font-style: italic;">C:\Program Files\Research In Motion\BlackBerry Device Simulators 4.2.2\4.2.2.114 (8300-Vodafone)</span>:<br /><br />* dmp files<br />* debug, cod, csl, cso, jar files of your applications<br /><br />This works when the installed simulator does not have the solution #2 i.e. clean.bat is absent in the simulator's directory.<br /><br /><a href="http://www.blackberryforums.com/developer-forum/140033-blackberry-simulator.html">Solution #4</a>: If you're using the JDE and wants your simulator reset each time you run it, go to <span style="font-style: italic;">Edit->Preferences</span>; <span style="font-style: italic;">Simulator</span> tab; <span style="font-style: italic;">Memory</span> sub-tab, and check <span style="font-style: italic;">"Reset the filesystem on startup"</span><br /><br /><br /></div>programmer.in.paradisehttp://www.blogger.com/profile/09333947381283175026noreply@blogger.com0