Saturday, April 9, 2011

code-cloning && other code smells in fast-paced Wall St

In fast-paced Wall St, you can copy-paste, as long as you remember how many places to keep in-sync. In stark contrast, my ex-colleague Chad pointed out that even a one-liner sybase API call should be made a shared routine and a choke point among several execution paths. If everyone uses this same routine to access the DB, then it's easier to change code. This is extreme DRYness. The opposite extreme is copy-paste or "code cloning" as some GS veteran described. Other wall st developers basically said Don't bother with refactoring. I'm extremely uncomfortable with such quick and dirty code smells, but under extreme delivery pressure, this is often the only way to hit deadlines. Similarly,

*Use global variables.
** -Use global static collections. Remember my collection of locks in my ECN OMS kernel?
** -Instead of passing local variables as arguments, make them static or instance fields.
** -Use database or env var as global variables.
** -Use spring context as global variables.

* Tolerate duplicate variables (and functions) serving the same purpose. Don't bother to refactor, simplify or clean up. Who cares about readablility? Not your boss! Maybe the next maintainer but don't assume that.
** Given the requirement that a subclass field and a parent field pointing to the same object, due to bugs, sometimes they don't. Best solution is to clean up the subclass, but don't bother.
** 2 fields (out of 100) should always point to the same object, but due to bugs, sometimes they don't. Best solution is to remove one, but don't bother.
** a field and a field of a method param should always point to the same object, so the field in the param's class is completely unnecessary distraction. Should clean up the param's class, but don't bother.
** a field and method parameter actually serve the same purpose.
*** maybe they refer to the same object, so the method param is nothing but noise. Tolerate the noise.
** tolerate a large number (100's) of similar methods in the same class. Best to consolidate them to one, but don't bother.
** tolerate many similar methods across classes. Don't bother to consolidate them.
** tolerate tons of unused variables. Sometimes IDE can't even detect those.

- use macro to substitute a checked version of vector/string. It's cleaner but more work to use non-macro solutions.
- don't bother with any validation until someone complains. Now, validation is often the main job of an entire applicaiton, but if your boss doesn't require you to validate, then don't bother. If things break, blame upstream or downstream for not validating. Use GarbageInGarbageOut as your defence.
- VeryLongVeryUgly methods, with multi-level nested if/while
- VLVU signatures, making it hard to understand (the 20 arguments in) a CALL to such a method.
- many methods could be made static to simplify usage -- no need to construct these objects 9,999 times. It's quite safe to refactor, but don't bother to refactor.
- Don't bother with null checks. You often don't know how to handle nulls. You need to ask around why the nulls -- extra work, thankless. If you can pass UAT, then NPE is (supposedly) unlikely. If it happens in production, you aren't the only guy to blame. But if you finish your projects too slow, you can really suffer.
- Don't bother with return value checks. Again, use UAT as your shield.
- use goto or exceptions to break out of loops and call stacks. Use exception for random jump.
- Ignore composed method pattern. Tolerate super long methods.
-Use if/else rather than virtual functions
-Use map of (String,Object) as cheap value objects
-Forget about DRY (Don't Repeat Yourself)
-Tolerate super long signatures for constructors, rather than builder pattern ( [[EffectiveJava]] )
- don't bother to close jdbc connections in the finally block
- open and close jdbc connections whenever you like. Don't bother to reuse connections. Hurts performance but who cares:)
-Don't pass jdbc connections or jdbcTemplates. In any context use a public static method to get hold of a connection.
- create new objects whenever you feel like, instead of efficiently reuse. Of course stateless objects can be safely reused, creating new ones are cheap. It hurts performance but who cares about performance?
-Use spring queryForMap() whenever convenience
- Tolerate tons of similar anon inner classes that should be consolidated
- Tolerate 4 levels of inner classes (due to copy-paste).
- Don't bother with thread pools. Create any number of threads any time you need them.
- tolerate clusters of objects. No need to make a glue class for them
-Use public mutable fields; Don't both with getters/setters
-JMX to open a backdoor into production JVM. Don't insist on password control.
-print line# and method name in log4j. Don't worry about performance hit
-Don't bother with factory methods; call ctor whenever quick and dirty
-Don't bother with immutables.
- tolerate outdated, misleading source documentation. Don't bother to update. Who cares:)
- some documentations across classes contradict each other. Don't bother to straighten.

No comments:

Total Pageviews

my favorite topics (labels)

_fuxi (302) _misLabel (13) _orig? (3) _rm (2) _vague (2) clarified (58) cpp (39) cpp_const (22) cpp_real (76) cpp/java/c# (101) cppBig4 (54) cppSmartPtr (35) cppSTL (33) cppSTL_itr (27) cppSTL_real (26) cppTemplate (28) creditMkt (14) db (65) db_sybase (43) deepUnder (31) dotnet (20) ECN (27) econ/bank` (36) fin/sys_misc (43) finGreek (34) finReal (45) finRisk (30) finTechDesign (46) finTechMisc (32) finVol (66) FixedIncom (28) fMath (7) fMathOption (33) fMathStoch (67) forex (39) gr8IV_Q (46) GTD_skill (15) GUI_event (30) inMemDB (42) intuit_math (41) intuitFinance (57) javaMisc (68) javaServerSide (13) lambda/delegate (22) marketData (28) math (10) mathStat (55) memIssue (8) memMgmt (66) metaProgram` (6) OO_Design (84) original_content (749) polymorphic/vptr (40) productive (21) ptr/ref (48) py (28) reflect (8) script`/unix (82) socket/stream (39) subquery/join (30) subvert (13) swing/wpf (9) sysProgram` (16) thread (164) thread_CAS (15) thread_cpp (28) Thread* (22) timeSaver (80) transactional (23) tune (24) tuneDB (40) tuneLatency (30) z_ajax (9) z_algoDataStruct (41) z_arch (26) z_arch_job (27) z_automateTest (17) z_autoTrad` (19) z_bestPractice (39) z_bold (83) z_bondMath (35) z_book (18) z_boost (19) z_byRef^Val (32) z_c#GUI (43) z_c#misc (80) z_cast/convert (28) z_container (67) z_cStr/arr (39) z_Favorite* (8) z_FIX (15) z_forex (48) z_fwd_Deal (18) z_gz=job (33) z_gzBig20 (13) z_gzMgr (13) z_gzPain (20) z_gzThreat (19) z_hib (19) z_IDE (52) z_ikm (5) z_IR_misc (36) z_IRS (26) z_javaWeb (28) z_jdbc (10) z_jobFinTech (46) z_jobHunt (20) z_jobRealXp (10) z_jobStrength (15) z_jobUS^asia (27) z_letter (42) z_linq (10) z_memberHid` (11) z_MOM (54) z_nestedClass (5) z_oq (24) z_PCP (12) z_pearl (1) z_php (20) z_prodSupport (7) z_py (31) z_quant (14) z_regex (8) z_rv (38) z_skillist (48) z_slic`Problem (6) z_SOA (14) z_spring (25) z_src_code (8) z_swingMisc (50) z_swingTable (26) z_unpublish (2) z_VBA/Excel (8) z_windoz (17) z_wpfCommand (9)

About Me

New York (Time Square), NY, United States