Categories
Software development

Tree, recursive function and my dumb mistake

Reading Time: < 1 minute

Tree data structure is fairly common in software development, and luckily I have quite a bit experience working on those in my career. I started working on this as I was working for UGS/Siemens PLM Software, and I was involved in the development of XML based data adapter for CAD data exchange, a key piece of information we want to translate is the assembly information, or product structure, or in computer/software terms, the tree hierarchy. I did learned a few things on recursive function, etc. Interestingly enough, later on I got a interview phone call from Google, and the guy asked me about recursion, for a simple problem like this: basically they are 100 matches, every time one can take one or 2, how many combinations are there? I said let’s do it in recursive fashion, after quite a bit reminder/hint, finally I said n(100) = n(99) + n(98)

But they were not very impressed with me, as I did not come up with the solutions fast enough, which is fine. I am who I am, I can work on those kind of interesting problems, in my own pace. Or explained in my Chinese name, it’s getting faster gradually 🙂

My dumb mistake

Categories
Software development

Test Driven Development and Unit Test

Reading Time: 2 minutes

(Update 02-19-2021)

spring.io Testing the Web Layer

Mockito Example with Best Practices

JUnit and Mockito : Best Practices, Do’s and Don’ts

(Original) Test Driven Development (TDD) is getting popular these days. I had opportunity to being exposed it recently. I am not new to unit test. In the software company I worked for 8 years, we have regression test suites that runs automatically (at least daily), and we update the test suites as we find edge cases from customer bug reports, or in our development. That was about 8 years ago. Since the switch into Java land (2010), I started using JUnit and create/run the unit tests. One thing I was exposed to recently is Mocking in unit test, and TDD. Both takes a little time, and I am not fully bought into TDD yet. But I did learned something interesting on both topics lately, and like to share.

1) TDD
One of my coworker is very experienced and in-grained in this, as we are doing pair programming, I learned this a bit. An interesting back and forth as I was making changes to a method.

Coworker: “Do you have a test case?”
Me: test case for what?
Coworker: for the change?
Me: do we need this? …

But eventually we wrote the case, magically the web app also worked as soon as we passed the unit test. But overall I still have some reservation to do this, as I am not good at mocking e.g. Mockito, or writing test, and I think there is some cases pair programming can get the code right without go heavy in unit test.

Some links for mockito and spring test

Stubbing and Mocking with Mockito and JUnit


https://www.vogella.com/tutorials/Mockito/article.html
https://stackoverflow.com/questions/39486521/how-do-i-mock-a-rest-template-exchange
https://www.baeldung.com/spring-mock-rest-template
https://stackoverflow.com/questions/11969609/junit-mockito-when-thenreturn-throws-nullpointerexception/18060451
https://javacodehouse.com/blog/mockito-tutorial/

2) Unit test (auto test suites)
I heard from my coworker recently that test suites should not use the implementation data source (database). I thought the main reason is the heavy weight/use from database resources point of view. But there is more, today I found if auto test consistently changes things on dev database, it’s really hard to find out the root cause, and cause confusion. Initially we thought the problem was caused by batch job, or the web app, spent a lot time trying to figure out, both are not the cause. And luckily, at the end we were able to find out the real cause.

Categories
Software development

If it’s not broken, don’t fix it?

Reading Time: < 1 minute

This is the common saying I heard a lot when I started worked for a software company on development. I can list some of the pros and cons of fix it.

Pros
Architecture chaos: if not fixing it, basically as the software ages, per the “broken windows” theory, people would just throw in changes to get things done, without carefully thinking about the architecture, dependencies. And this leads to the related problem below.

Code hard to maintain: it will become harder and harder to fix bugs, or add new features with the code in a messy state.

Cons
Introduce new bugs by accident. Or the fix making the software worse. While it’s unlikely, it’s still possible. Not carefully planned fix could introduce bugs, and make the software worse. I have done my share of that too 🙁

Refactor
If we were to work on the clean up, refactor the code, as a minimum we should have the regression test suites. Or in ideal world, we would have automated unit tests, which could help both speed up development, and give another level of confidence for the code change.

Categories
iPhone app Software development

Why unit test?

Reading Time: 2 minutes

For the pretty reports?
About a year ago, I worked for a client for an iOS project. The developer I worked with is very enthusiastic about unit testing, test driven development. I recall he used some tool (lcov, stands for line coverage), and set up the build script such that the unit test and lcov runs frequently. I was also shown the pretty chart created by lcov. All is good. except one day, I found a utility function I wrote was broken in the iPad simulator. Turns out the developer modified the code and added test for that function (a good thing), but at the same time forgot to run the real thing to check it.

Real motivation for unit testing
I think the unit test as another perspective to verify the code works as desired, this is from my own experience. I recall we have regression test suites in the software company I first worked professionally, that was more than 10 years ago! I started with waterfall, slowly transitioned into agile, test driven development. When we found new test cases (from problem report, etc.), we added those to our regression test suites as we see fit. We ran those unit testing suites before checking in code. This does not means the product we are developing is prefect, but it does give me more confidence as we add features or do bug fixes. This is also true in the many JUnit tests I saw/added in many places I worked since then.

More recently, as I saw the “mock” concept in JUnit, while I am not expert on “mocking”. Conceptually I liked this idea, as we don’t want to repeat the same thing in the production code, we add one more perspective. I also recall the famous investor Charlie Munger (Vice chair of Berkshire Hathaway) once said, he used at least two models to value a company/investment. Check and balance.

(Update) Came across this article on the disadvantages of pair programming. Also, saw this launchCodeSTL a while ago.

Categories
Software development Web

Spring MVC, Maven

Reading Time: 2 minutes

I’m back to Java world again, after about 2 years stint on Objective-C and iOS development. I’m not new to Java land, as I have done Java work between 2010 and 2011, for 2 years.

My personal learning experience:
JSF => Spring MVC (jspx is still very similar): I have done JSF, which is a component based Java web framework, we know Spring MVC is different: it’s based on REST, GET, POST, and mapping etc. Luckily I have done RESTful web services in my past work, and used those services from iOS side. Another new thing at client side is javascript, and jQuery, I recall I used Richfaces (extension of JSF) for the AJAX, they are not javascript though.

IBM web sphere/Rational application developer RAD, CVS => Spring STS, SVN, note both RAD/STS are based on Eclipse: for the application server, and development IDE, the transition is easier such they are very similar.

Ant (build.xml) => Maven (pom.xml): this is a big change, actually. Maven has some learning curve, also with the Nexus repository. My only past experience using Maven: use Netbeans to open the project (pom.xml file). I found the following two tutorials helpful.

Tutorial on Maven:
http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

http://maven.apache.org/guides/getting-started/

Spring MVC: using the Get Started Guide from the dashboard, or the link here.

Obviously, learn as much as possible from the work itself, from coworkers etc. The good thing is my current work place is one of the most collaborative places I’ve ever worked. This makes my life a bit easier 🙂

Repository, Nexus (Sonatype), JFrog Artifactory

JFrog intro: quick youtube video

Comparison between Nexus and JFrog

Sonatype Nexus

Josh Long A Bootiful Podcast : Hi, Spring fans! In this installment Josh Long (@starbuxman) talks about ten years on the Spring team, reactive support, and RSocket support in Spring Integration, his upcoming appearances at SpringOne and his upcoming YOW! workshop on Cloud Native Java, and then talks to JFrog’s Baruch Sadogursky (@jbaruch) about continuous delivery, DevOps, Java artifact management Artifactory, and more.

General questions about JFrog artifactory

Categories
Software development

Bug fixing vs. new development

Reading Time: 2 minutesIn my 13+ years of software development career, I have done both. So which one do I prefer? This is a bit like asking my daughter: who do you like more, mommy or daddy? (I will reveal my daughter’s answer at the end.)

I think both are interesting work, and both could be challenging. If you ask me pick one, I will probably pick the new development, as most developers like to work on new things: from new technologies to new features, new project/product. But from time to time, I have worked on some bug fixing work that is not only interesting, but also challenging and rewarding (mentally not financially, as I worked for companies all these years). I recall 6, 7 years ago, when I was working for CAD software company, we had two bugs to fix, the first one is actually not too bad, essentially it’s a tolerance problem. In other words, I just need to make sure when it checks whether the X, Y, Z axis is orthogonal to each other, I gave some tolerance. I did cross products of vectors, borrowing from similar experience I learned at work.

The second one, is a bit daunting, to say the least. Essentially we have about 2 weeks to fix a nasty problem in a CAD translator, and we don’t have any clue why the results is wrong. By working with 3rd party, and looking carefully at the problem, some teamwork, I was able to solve the mystery when I was working remotely at Shanghai. I recall I could not fall asleep that night, as I knew that’s a tough problem and will help the sales team greatly to sell into a top Europe car maker.

I had similar experience most recently, although it’s a totally different problem, and we as developers also work in much different world: with stackoverflow.com, and google search (blogs).

So back to my daughter’s answer to my silly question: most of times she will say mommy and daddy; sometimes she will say “don’t ask silly questions”.

PS: in some places bug fixing is also called as maintenance. Just like the car maintenance, software also needs regular check-up and fix 🙂

Categories
iPhone app Software development

Code signing error in Xcode

Reading Time: 2 minutes(Update 08-Dec-2020) Things I learned today (or tomorrow am 🙂

  1. One team can have at most two distribution certs
  2. In Xcode sign in as agent without the (mail.com or gmail.com after @) because it appears my apple id is just the id without all the @ + dot com stuff. That alone cost me probably one hour. Plus the one hour I tried to export cert in old MacBook, then move it over to the new MacBook. So totally 2 hours wasted… after those two steps, I was able to go back to automatically signing and validate my archive (ipa) for myNestEgg…

Managing a Distribution Certificate

No signing certificate “iOS Distribution” found

Create, export, and delete signing certificates

====

For organizations, if a distribution certificate is missing a private key or not in your keychain, you can email the creator of the signing certificate. Ask the creator to export the signing certificate on their Mac so you can install it on your Mac. (To install a certificate in your keychain, double-click the exported certificate file.)

====

What is app signing?

Creating the iOS Distribution Certificate

iOS – Creating a Distribution Certificate and .p12 File

(Original 06-Feb-2013) Had my share of code signing problem (esp. the enterprise distribution certificate) in my Xcode development. Luckily, stackoverflow rescued me as always. It seems a lot problem is due to the Xcode upgrade, project name change, provision profile/distribute certificate expiring etc. And the solution is usually delete or comment out the offending line. Like below. To go to the project file, I usually do in the command line, “cd projectName.xcodeproj”, then “vi project.pbxproj”.

http://stackoverflow.com/questions/1760518/codesign-error-provisioning-profile-cannot-be-found-after-deleting-expired-prof

http://stackoverflow.com/questions/5758154/code-sign-error-provisioning-profile-cant-be-found

I encountered another problem related to the provisioning profile expiration, the distribute certificate appears twice in the Keychain, even after I deleted it explicitly. It turns out the old distribute certificate came back after I opened the project in Xcode (presumedly it came back when the old provision profile associated with the project got loaded). So the workaround is to delete the old distribute certificate again after opening the project in Xcode.

http://stackoverflow.com/questions/5932522/codesign-error-certificate-identity-appearing-twice

Btw, saw an interesting idea from Mobile Iron regarding the enterprise distribution certificate. Normally the certificate expires in a year. In last 30 days it will prompt the user something like “the provision profile will expire in a few days…”, not good user experience. There is no way to renew it before it expires either. So the workaround suggested by MI is create 2 certificates, and create the second 6 months before the expiration and have user update the app. This way, essentially the app got extended 6 months. And so on. There is one catch in Xcode 4.3.3 I am using. It only recognizes the provision profile that was created earlier (or expires earlier). The workaround there is delete the earlier provision profile 😀

Categories
Software development Web Windows

Consuming a PHP SOAP web service from C# client

Reading Time: < 1 minuteI need to create a SOAP client in C#, and in order to test it I need a SOAP web service. Since my hosting company uses MySQL/PHP technology stack, I am using this PHP Soap web service example.

For the C# soap client, I am following this example on stackoverflow. But there is one problem when I tried to run the example. I got the error (exception) like the following:
The content type text/xml; charset=ISO-8859-1 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly.

Again I found this thread on stackoverflow which seems relevant. It talked about the custom message encoder developed by Microsoft, and Paul Morgado’s addition to the CustomTextMessageEncoder class (just add his method at the end of the class). There is one more thing, the configuration file for the app. In my case, it’s something like the following: (note the messageVersion and bindingElementExtensions definition, there was some error in the Microsoft documentation regarding the latter one).

Categories
Software development

Set up SVN (Subversion) on local machine (Windows)

Reading Time: < 1 minuteI need to do some development work on Windows, using Visual Studio. I like to have a simple source code control system, in recent years I have used CVS, Subversion and git (on Mac). I did a google search on Subversion and found some instructions regarding setting up Subversion.

Setting up Subversion on Windows

and this one

Installing and Configuring SVNServe and TortoiseSVN on Windows

Download/install the SVN server and starting the windows service was relatively straightforward. So as the Tortoise SVN client. Couple things keep in mind:

1) Some sites requires registration or install additional software, I chose sites that does not require registration.

2) I found sometimes I can not open up svn://localhost successfully, in the same command prompt window where I start the SVN service. After I close the command prompt and tried again, it worked. The commands I used are:

set SVN_EDITOR=c:\windows\system32\notepad.exe
svn mkdir svn://localhost/myproject

Categories
Software development

Some Oracle and Java interview questions

Reading Time: 4 minutes(Update 02-27-2019) It’s 5 and half years since last update. And two more jobs for me :] Noticed from recent job search in STL, code exercise and code testing (at the spot, pair programming, TDD) is becoming common now in STL, which is unthink of 5.5 years back. I did add a few blog posts on this fronts recently.

Javascript jasmine node.js based testing

Code exercise : linear chamber animation / simulation

Spring, Spring Boot and React

Also, on pure concepts side, Java (J2SE) and J2EE (Spring and Hibernate) are still important and questions were asked around both areas too.

Example questions:
JPA annotations
Hibernate configuration (XML file)
OOP Concepts
Java Interface vs Abstract class (do we need to implement abstract method to use the class)
final finally finalize java
spring model view controller annotation
classpath loading

(Updated 08-31-2013) For those brave hearts venture out the silicon valley/seattle, here is the must-do homework (LeetCode). Chinese version (here and here).

(Original)
Oracle
SQL: Inner join and out join

Function, (stored) procedure and package

What is a trigger in Oracle

“…Oracle lets you define procedures called triggers that run implicitly when an INSERT, UPDATE, or DELETE statement is issued against the associated table or, in some cases, against a view, or when database system actions occur. These procedures can be written in PL/SQL or Java and stored in the database, or they can be written as C callouts.

Triggers are similar to stored procedures. A trigger stored in the database can include SQL and PL/SQL or Java statements to run as a unit and can invoke stored procedures. However, procedures and triggers differ in the way that they are invoked. A procedure is explicitly run by a user, application, or trigger. Triggers are implicitly fired by Oracle when a triggering event occurs, no matter which user is connected or which application is being used…”

A shorter version at orafaq forum

Longer version at orafaq.com/wiki

7. Compare and contrast TRUNCATE and DELETE for a table.
Both the truncate and delete command have the desired outcome of getting rid of all the rows in a table. The difference between the two is that the truncate command is a DDL operation and just moves the high water mark and produces a now rollback. The delete command, on the other hand, is a DML operation, which will produce a rollback and thus take longer to complete.

8. Give the reasoning behind using an index.
Faster access to data blocks in a table.

11. Give some examples of the types of database contraints you may find in Oracle and indicate their purpose.
A Primary or Unique Key can be used to enforce uniqueness on one or more columns.
A Referential Integrity Contraint can be used to enforce a Foreign Key relationship between two tables.
A Not Null constraint – to ensure a value is entered in a column
A Value Constraint – to check a column value against a specific set of values.

DDL vs DML
Data Definition Language (DDL) statements are used to define the database structure or schema. Some examples:
CREATE – to create objects in the database
ALTER – alters the structure of the database
DROP – delete objects from the database
TRUNCATE – remove all records from a table, including all spaces allocated for the records are removed
COMMENT – add comments to the data dictionary
RENAME – rename an object

Data Manipulation Language (DML) statements are used for managing data within schema objects. Some examples:
SELECT – retrieve data from the a database
INSERT – insert data into a table
UPDATE – updates existing data within a table
DELETE – deletes all records from a table, the space for the records remain
MERGE – UPSERT operation (insert or update)
CALL – call a PL/SQL or Java subprogram
EXPLAIN PLAN – explain access path to data
LOCK TABLE – control concurrency

1. Describe the difference between a procedure, function and anonymous pl/sql block. Candidate should mention use of DECLARE statement, a function must return a value while a procedure doesn?t have to.

PL/SQL developer vs. Toad

Reporting
SQL Server Reporting Services (Microsoft); SQL Server Reporting Services (wiki)

Oracle 10g reports (PDF); Oracle Reports Tutorial

LIMS (wiki)

Java
(Updated 08-31-2013) OOPS Interview Questions

Top 20 Core Java Interview questions answers asked in Investment Bank

(Original) 30 Core Java questions (sys-con)

J2EE interview questions (techInterviews.com)

more j2ee interview questions

Java: hashMap and hashTable

Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones.

Difference between Get and Post method on web (link one)

Lazy initialization, dependency injection

3 Things in OO:
data encapsulation, polymorphism, dynamic dispatch (when a method is invoked on an object, the object itself determines what code gets executed by looking up the method at run time in a table associated with the object. This feature distinguishes an object from an abstract data type (or module), which has a fixed (static) implementation of the operations for all instances. It is a programming methodology that gives modular component development while at the same time being very efficient.)

How to use static method? (Include class name)

Aggregation

Throwable interface (exception)

What is reflection

Interface vs. abstract class
non-static method
final: immutable, e.g. String
finalized method

tree-reflection