Coding Therapy for Software Developers Steven Feuerstein PL/SQL Evangelist, Dell steven@stevenfeuerstein.com
I am not making light of therapy Therapy can be a very important and meaningful process for healing pain and distress. Oracle PL/SQL Programming I am not mocking real therapy nor do I suggest that my session today can substitute for a session with a real therapist. But perhaps I can help you with a few coderelated issues... Copyright 2013 Feuerstein and Associates Page 2
First, the Greatest Therapy of All. Grandchildren! Meet Loey. Copyright 2013 Feuerstein and Associates Page 3
Why might therapy help developers? Sure, some software is generated. But almost all software continues to be written directly by human beings. Software construction is a wholly intellectual endeavor. That is, to write software we rely almost exclusively on our brains. Consequently, human physiology and psychology play an enormous role in how software is written - and miswritten. Copyright 2013 Feuerstein and Associates Page 4
Coding Therapies for Today Game Therapy Learning through fun Dream Therapy Let your subconscious do the "heavy lifting." Confessional Therapy Don't be afraid to ask for help. Shock Therapy SQL is not your best friend. Couples Therapy Developer and Database Administrator Developer and Manager And. Species Therapy! Copyright 2013 Feuerstein and Associates Page 5
Game Therapy Games can be quite helpful in the learning process. We like to compete (even if only against ourselves), have fun, win prizes. Mastermind Classic of deductive logic Will improve your debugging skills Set (www.setgame.com) Pattern analysis and resolution Will generally improve your development skills and quality of code. PL/SQL Challenge Best of both worlds. Games + PL/SQL Copyright 2013 Feuerstein and Associates Page 6
Dream therapy for developers The worst way to deal with a problem is to worry at it (for hours or days). Sometimes conscious attention only makes it harder to find the solution. Maybe you should sleep on it, instead. There's a good chance that when you wake up the answer will be waiting in your conscious "in box." Copyright 2013 Feuerstein and Associates Page 7
Change the Body, Change the Mind Change what your body does, and you change how your mind works. If you can't go to bed and you're stuck on a problem, then... Take a walk, run around the block, do some stretches or sit-ups, anything but stare at your screen. Best of all: leave the sterile environment of computers and get out into the world. We spend almost all of our time completely, physically disconnected from our own planet. Oracle PL/SQL Programming Copyright 2013 Feuerstein and Associates Page 8
Confessional Therapy "Predators look for signs of illness or weakness when choosing their prey, so a prey animal needs to appear healthy, or it will be a sure target. By the time they are showing signs of disease, in many instances, the birds have become too weak to be able to disguise it." - From peteducation.com Our evolved survival instinct urges us to hide weakness. On top of that, we software developers are supposed to be really smart. We are the wizards of modern society. Unfortunately, ignorance leads directly to bugs and sub-optimal code. Copyright 2013 Feuerstein and Associates Page 9
It's OK to say "I don't know. Help me!" Just thinking about asking for help will often do the trick. Most people like to be asked to help. It makes them feel valued. It strengthens the team as a whole. It may not really matter who you ask for help. If there are no programmers handy, ask your spouse or parent or child to be a sounding board. Or write an email. By the time you finish writing it, you will likely have found the answer to your problem. The important thing is to get the issue out of your head. Copyright 2013 Feuerstein and Associates Page 10
Follow the Thirty Minute Rule We are usually too deeply inside (and part of) the problem to step back and take a fresh look. If you can't fix a bug in 30 minutes, ask for help. For "trivial" bugs, "give up" after just a few minutes! Senior developers and managers must take the lead. Ask more junior members for help. Show that you are fallible, that you can learn from anyone and everyone. Copyright 2013 Feuerstein and Associates Page 11
Shock Therapy Sometimes you need to be given a shock to be able to break out of your ruts, and gain a new perspective on your life. Same with software. Consider some of the things we say about. It's so easy to write SQL in PL/SQL! This INSERT will never raise a DUP_VAL error. Oracle will optimize it all for me automagically. SQL No one else will ever need to write a SQL statement like this. Copyright 2013 Feuerstein and Associates Page 12
What? No SQL for PL/SQL developers? Well.sort of. You should avoid writing SQL statements all over your application. Every SQL statement you write is a hard-coding. And a more dangerous, problematic hard-coding than hard-coded literals. You shouldn't repeat "170546" and you shouldn't repeat "SELECT * FROM..." Yes, I know: shocking! Copyright 2013 Feuerstein and Associates Page 13
What's a PL/SQL developer to do? Oracle PL/SQL Programming Create a separate data access layer, an API. Instead of writing SQL statements, call functions and procedures that do the work for you (SQL as a service)... Hiding your implementation (it will change) Strengthening your error handling (you only write it or generate it once) Increasing your productivity. Look for ways to generate as much of this code as you can. 11g_emplu.pkg Copyright 2013 Feuerstein and Associates Page 14
More shocks to the system... You should consider every hard-coded VARCHAR2(N) declaration to be a bug. Unless it's the "single point of definition." DECLARE l_full_name VARCHAR2(100) := first_name_in ' ' last_name_in; l_big_string VARCHAR2(32767); Three bugs! What should you do instead? Use %TYPE, %ROWTYPE and SUBTYPEs. DECLARE l_full_name employees_rp.full_name_t := employees_rp.full_name (first_name_in, last_name_in); l_big_string plsql_limits.maxvarchar2_t; plsql_limits.pks explimpl.pkg Copyright 2013 Feuerstein and Associates Page 15
Couples Therapy: Developer and DBA Can't we all just get along? Apparently not... Developer: "Why can't I just [ add that column drop that table mess things up ] whenever I want?" DBA: "Add an index? Ha! First, tune your code." Stay on good terms with your DBA. Let's face it; a DBA has lots more responsibility and privileges (which translate to "power" in a database). You can't win a battle with a DBA. Application development should be a collaborative process. Copyright 2013 Feuerstein and Associates Page 16
Developer and DBA: a close collaboration is best As you change the way you write your code, you should notify your DBA. Start to work with collections? Notify! Using FORALL and BULK COLLECT? Notify! Discovered Oracle11g function result cache? Notify! Ask (negotiate) for the resources you need to analyze code impact yourself. For example, with access to just a handful of V$ views, you can monitor PGA memory utilization of your PL/SQL code. plsql_memory.pkg grantv$.sql 11g_frc*.* Copyright 2013 Feuerstein and Associates Page 17
Couples Therapy: Developer and Manager Are you satisfied with the way your manager communicates with you? Which of these does your manager ask: How can I help you get your job done? How maintainable is your code? When will you be done? How thoroughly have you tested your code? Can you make it go faster? Did you follow the coding standards? Copyright 2013 Feuerstein and Associates Page 18
Developer and Manager: Pretense is Critical Seems like some managers need to know that you, the developer, know "who's boss." Even though, really, the only point of a manager is to help you succeed (after all, who does the real work?). So avoid direct challenges to authority and instead... Copyright 2013 Feuerstein and Associates Page 19
"Thank You For Being a Great Manager!" Buy your manager a copy of Peopleware as a thank you gift. A classic text for building dev teams Ask frequently for help, advice and direction. "How can I improve my testing?" Ask for standards and mechanisms to verify that you are following them. Standards improve your quality of programming life. Copyright 2013 Feuerstein and Associates Page 20
Species Therapy Humanity, most notably the "civilized" version, is a slow-motion extinction event, the 6 th in Earth's history. Goodbye bees, coral, bats, diversity All for the sake of our comfort and convenience. But don't worry! We'll just build spaceships and find another planet! Copyright 2013 Feuerstein and Associates Page 21
It's probably too late, but We need to get over ourselves. Reduce Recycling is OK,but it is post-consumer. What a surprise! Better to reduce the burden you/we place on the world. Repair We have done grave damage. But there are lot of "hands" out there to fix things. My focus: invasive species. Copyright 2013 Feuerstein and Associates Page 22
Coding Therapy: You can't escape your own brain and you can't escape your body. Our brains' physiology and psychology have an unavoidable and large impact on the way we write code. Don't fight it; instead, understand it, accept it, adapt to it. You will be happier and your code will be better. Copyright 2013 Feuerstein and Associates Page 23