Ask for code samples, skip the coding tests during the interview

I always ask for code samples when interviewing a new technical candidate. I rarely ask for people to code during an interview.

Asking people to code well can easily become an exercise in how well they have a language memorized. Quite honestly, I have forgotten bits of languages that I no longer need. I am occasionally surprised, a few days ago I helped another developer by remembering about ‘cpp’. [1]

A code sample shows a candidate at their best (or worse):

  • They have time to do the code right.
  • Google is at their disposal.
  • They can test the code.
  • Do they comment?
  • Do they use meaningful variable names?

The code sample allows you to avoid mental traps:

  • The smooth-talker
  • The pretty face (both sexes)
  • The “everyone else liked the candidate” conformity

With 5 minutes or less to code a solution, you get sloppy code that does not reveal their true ability to code.

If someone’s sample code is pretty much as good as it gets for them. Ugly sample code means ugly code in *your code base* if you hire them.

A simple test to see how good that Java developer is.

Another question developer candidates

Below the fold for a real sample of bad coding. Can you find the issues?

[1] (cpp is the standalone program that C uses as its preprocessor. Running cpp allows you to see the post preprocessing text to be sent to the C compiler)

import org.hibernate.Session;
import org.hibernate.Transaction;
import prf.hibernate.SessionFactoryUtil;

public class DBTrans {
    final static Session session = SessionFactoryUtil.getInstance().getCurrentSession();
    public static Coverage cov = null;
    public static ProductLKP product = null;
    public static CoverageNetworkTier covnetier = null;
    public static NetworkTierLKP netierlkp = null;
    public static DrugCopayTypeLKP dct = null;
    private static Transaction tx = null;

    public DBTrans() {
    }

    public static Coverage getCoverage(int coverageId) {
        try {
            tx = session.beginTransaction();

            cov = (Coverage) session
                    .createQuery("select c from Coverage c where c.coverage_id = :id")
                    .setParameter("id", coverageId)
                    .uniqueResult();
            return cov;

        } catch (RuntimeException e) {
            System.out.println("\n\nException [DBTrans.getCoverage]: " + e.getMessage() + "\n\n");
            return null;
        }
    }

    public static ProductLKP getProduct(int coverage_product_id) {
        try {
            product = (ProductLKP) session
                    .createQuery("select p from ProductLKP p where p.product_id = :id")
                    .setParameter("id", coverage_product_id)
                    .uniqueResult();

            return product;
        } catch (RuntimeException e) {
            System.out.println("\n\nException [DBTrans.getProduct]: " + e.getMessage() + "\n\n");
            return null;
        }
    }

    public static CoverageNetworkTier getCovnetier(int coverage_id) {
        try {
            covnetier = (CoverageNetworkTier) session
                    .createQuery("select cnt from CoverageNetworkTier cnt where cnt.coverage_id = :id")
                    .setParameter("id", coverage_id)
                    .uniqueResult();
            return covnetier;
        } catch (RuntimeException e) {
            System.out.println("\n\nException [DBTrans.getCovnetier]: " + e.getMessage() + "\n\n");
            return null;
        }
    }

    public static NetworkTierLKP getNetierlkp(int covnetier_network_tier_id) {
        try {
            netierlkp = (NetworkTierLKP) session
                    .createQuery("select ntlkp from NetworkTierLKP ntlkp where ntlkp.network_tier_id = :id")
                    .setParameter("id", covnetier_network_tier_id)
                    .uniqueResult();
            return netierlkp;

        } catch (RuntimeException e) {
            System.out.println("\n\nException [DBTrans.getNetierlkp]: " + e.getMessage() + "\n\n");
            return null;
        }
    }

    public static DrugCopayTypeLKP getDct(int coverage_drug_copay_type_id) {
        try {
            dct = (DrugCopayTypeLKP) session
                    .createQuery("select dct from DrugCopayTypeLKP dct where dct.drug_copay_type_id = :id")
                    .setParameter("id", coverage_drug_copay_type_id)
                    .uniqueResult();
            return dct;
        } catch (RuntimeException e) {
            System.out.println("\n\nException [DBTrans.getDct]: " + e.getMessage() + "\n\n");
            return null;
        }
    }

    public static boolean updateCoverage(Coverage cov) {
        try {
            session.update(cov);
            tx.commit();
            return true;
        } catch (RuntimeException e) {
            System.out.println("\n\nException [DBTrans.updateCoverage]: " + e.getMessage() + "\n\n");
        }
        return false;
    }

    public static void closeSession() {
        session.close();
    }

    public static void showData() {
        System.out.println("Coverage ID: " + cov.getCoverage_id());
        System.out.println("Product: " + product.getProduct_name());
        System.out.println("Effective Date: " + cov.getContract_eff_from_date());
        System.out.println("\n*" + netierlkp.getName());
        System.out.println("Individual Deductible: " + covnetier.getIndividual_deductible());
        System.out.println("Family Deductible: " + covnetier.getFamily_deductible());
        System.out.println("OOP Limit Individual: " + covnetier.getOop_limit_individual());
        System.out.println("OOP Limit Family: " + covnetier.getOop_limit_family());
        System.out.println("Coinsurance Percent: " + covnetier.getCoinsurance_percent());
        System.out.println("\nPrimary Care Copay: " + covnetier.getPrimary_care_copay());
        System.out.println("Specialty Care Copay: " + covnetier.getSpecialty_care_copay());
        System.out.println("Urgent Care Copay: " + covnetier.getUrgent_care_copay());
        System.out.println("Xray Lab Copay: " + covnetier.getXray_lab_copay());
        System.out.println("ER Copay: " + covnetier.getEr_copay());
        System.out.println("OP Imaging Copay: " + covnetier.getOp_imaging_copay());
        System.out.println("OP urgery Copay: " + covnetier.getOp_surgery_copay());
        System.out.println("IP Admit Copay: " + covnetier.getIp_admit_copay());
        System.out.println("IP Day Copay: " + covnetier.getIp_day_copay());
        System.out.println("IP Max Days: " + covnetier.getIp_max_days());

        System.out.println("\n*" + dct.getDrug_copay_type_desc());
        System.out.println("Generic Drug Copay: " + covnetier.getGeneric_drug_copay());
        System.out.println("Brand Drug Copay: " + covnetier.getBrand_drug_copay());
        System.out.println("Non Brand Drug Copay: " + covnetier.getNon_brand_drug_copay());
        System.out.println("MO Generic Drug Copay: " + covnetier.getMo_generic_drug_copay());
        System.out.println("MO Brand Drug Copay: " + covnetier.getMo_brand_drug_copay());
        System.out.println("Specialty Drug Copay: " + covnetier.getSpecialty_drug_copay());
        System.out.println("Vision Copay: " + covnetier.getVision_copay());
        System.out.println("Lens Frame Allowance: " + covnetier.getLens_frame_allowance());
    }
}

This entry was posted in management, technical. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *