#! /usr/bin/python3 import datetime import hashlib prag_tips = [ 'Care About Your Craft', # Tip #1, pg. xxi # Why spend your life developing software unless you care about doing it well? 'Think! About Your Work', # Tip #2, pg. xxi # Turn off the autopilot and take control. Constantly critique and appraise your work. 'You Have Agency', # Tip #3, pg. 2 # It’s your life. Grab hold of it and make it what you want. 'Provide Options, Don’t Make Lame Excuses', # Tip #4, pg. 4 # Instead of excuses, provide options. Don’t say it can’t be done; explain what can be done. 'Don’t Live with Broken Windows', # Tip #5, pg. 7 # Fix bad designs, wrong decisions, and poor code when you see them. 'Be a Catalyst for Change', # Tip #6, pg. 9 #You can’t force change on people. Instead, show them how the future might be and help them participate in creating it. 'Remember the Big Picture', # Tip #7, pg. 10 # Don’t get so engrossed in the details that you forget to check what’s happening around you. 'Make Quality a Requirements Issue', # Tip #8, pg. 12 # Involve your users in determining the project’s real quality requirements. 'Invest Regularly in Your Knowledge Portfolio', # Tip #9, pg. 15 # Make learning a habit. 'Critically Analyze What You Read and Hear', # Tip #10, pg. 17 # Don’t be swayed by vendors, media hype, or dogma. Analyze information in terms of you and your project. 'English is Just Another Programming Language', # Tip #11, pg. 20 # Treat English as Just Another Programming Language. Write documents as you would write code: honor the DRY principle, ETC, automation, and so on. 'It’s Both What You Say and the Way You Say It', # Tip #12, pg. 22 # There’s no point in having great ideas if you don’t communicate them effectively. 'Build Documentation In, Don’t Bolt It On', # Tip #13, pg. 23 # Documentation created separately from code is less likely to be correct and up to date. 'Good Design Is Easier to Change Than Bad Design', # Tip #14, pg. 28 # A thing is well designed if it adapts to the people who use it. For code, that means it must adapt by changing. "DRY—Don't Repeat Yourself", # Tip #15, pg. 31 #Every piece of knowledge must have a single, unambiguous, authoritative representation within a system. 'Make It Easy to Reuse', # Tip #16, pg. 38 # If it’s easy to reuse, people will. Create an environment that supports reuse. 'Eliminate Effects Between Unrelated Things', # Tip #17, pg. 40 # Design components that are self-contained, independent, and have a single, well-defined purpose. 'There Are No Final Decisions', # Tip #18, pg. 48 # No decision is cast in stone. Instead, consider each as being written in the sand at the beach, and plan for change. 'Forgo Following Fads', # Tip #19, pg. 49 # Neal Ford says, “Yesterday’s Best Practice Becomes Tomorrow’s Antipattern.” Choose architectures based on fundamentals, not fashion. 'Use Tracer Bullets to Find the Target', # Tip #20, pg. 51 # Tracer bullets let you home in on your target by trying things and seeing how close they land. 'Prototype to Learn', # Tip #21, pg. 57 # Prototyping is a learning experience. Its value lies not in the code you produce, but in the lessons you learn. 'Program Close to the Problem Domain', # Tip #22, pg. 60 # Design and code in the language of the problem domain. 'Estimate to Avoid Surprises', # Tip #23, pg. 66 # Estimate before you start. You’ll spot potential problems up front. 'Iterate the Schedule with the Code', # Tip #24, pg. 70 # Use experience you gain as you implement to refine the project time scales. 'Keep Knowledge in Plain Text', # Tip #25, pg. 75 # Plain text won’t become obsolete. It helps leverage your work and simplifies debugging and testing. 'Use the Power of Command Shells', # Tip #26, pg. 79 # Use the shell when graphical user interfaces don’t cut it. 'Achieve Editor Fluency', # Tip #27, pg. 81 # An editor is your most important tool. Know how to make it do what you need, quickly and accurately. 'Always Use Version Control', # Tip #28, pg. 85 # Version control is a time machine for your work; you can go back. 'Fix the Problem, Not the Blame', # Tip #29, pg. 89 # It doesn’t really matter whether the bug is your fault or someone else’s—it is still your problem, and it still needs to be fixed. "Don't Panic", # Tip #30, pg. 89 # This is true for galactic hitchhikers and for developers. 'Failing Test Before Fixing Code', # Tip #31, pg. 91 # Create a focussed test that reveals the bug before you try fixing it. 'Read the Damn Error Message', # Tip #32, pg. 92 # Most exceptions tell both what failed and where it failed. If you’re lucky you might even get parameter values. "`select` Isn't Broken", # Tip #33, pg. 95 # It is rare to find a bug in the OS or the compiler, or even a third-party product or library. The bug is most likely in the application. "Don't Assume It—Prove It", # Tip #34, pg. 96 # Prove your assumptions in the actual environment—with real data and boundary conditions. 'Learn a Text Manipulation Language', # Tip #35, pg. 98 # You spend a large part of each day working with text. Why not have the computer do some of it for you? 'You Cant Write Perfect Software', # Tip #36, pg. 102 # Software can’t be perfect. Protect your code and users from the inevitable errors. 'Design with Contracts', # Tip #37, pg. 107 # Use contracts to document and verify that code does no more and no less than it claims to do. 'Crash Early', # Tip #38, pg. 113 # A dead program normally does a lot less damage than a crippled one. 'Use Assertions to Prevent the Impossible', # Tip #39, pg. 115: # If it can’t happen, use assertions to ensure that it won’t. Assertions validate your assumptions. Use them to protect your code from an uncertain world. 'Finish What You Start', # Tip #40, pg. 118 # Where possible, the function or object that allocates a resource should be responsible for deallocating it. 'Act Locally', # Tip #41, pg. 121 # Keep the scope of mutable variables and open resources short and easily visible. 'Take Small Steps—Always', # Tip #42, pg. 126 # Small steps always; check the feedback; and adjust before proceeding. 'Avoid Fortune-Telling', # Tip #43, pg. 127 # Only look ahead as far as you can see. 'Decoupled Code Is Easier to Change', # Tip #44, pg. 131 # Coupling ties things together, so that it’s harder to change just one thing. 'Tell, Don’t Ask', # Tip #45, pg. 132 # Don’t get values from an object, transform them, and then stick them back. Make the object do the work. 'Don’t Chain Method Calls', # Tip #46, pg. 134 # Try not to have more than one dot when you access something. 'Avoid Global Data', # Tip #47, pg. 136 # It’s like adding an extra parameter to every method. 'If It’s Important Enough To Be Global, Wrap It in an API', # Tip #48, pg. 136 # …but only if you really, really want it to be global. 'Programming Is About Code, But Programs Are About Data', # Tip #49, pg. 149 # All programs transform data, converting an input into an output. Start designing using transformations. 'Don’t Hoard State; Pass It Around', # Tip #50, pg. 153 # Don’t hang on to data within a function or module. Take one down and pass it around. "Don't Pay Inheritance Tax", # Tip #51, pg. 161 # Consider alternatives that better fit your needs, such as interfaces, delegation, or mixins 'Prefer Interfaces to Express Polymorphism', # Tip #52, pg. 162 # Interfaces make polymorphism explicit without the coupling introduced by inheritance. 'Delegate to Services: Has-A Trumps Is-A', # Tip #53, pg. 163 # Don’t inherit from services: contain them. 'Use Mixins to Share Functionality', # Tip #54, pg. 165 # Mixins add functionality to classes without the inheritance tax. Combine with interfaces for painless polymorphism. 'Parameterize Your App Using External Configuration', # Tip #55, pg. 166 # When code relies on values that may change after the application has gone live, keep those values external to the app. When you application will run in different environments, and potentially for different customers, keep the environment and customer specific values outside the app. 'Analyze Workflow to Improve Concurrency', # Tip #56, pg. 171 # Exploit concurrency in your user’s workflow. 'Shared State Is Incorrect State', # Tip #57, pg. 174 # Shared state opens a large can of worms that can often only be fixed by rebooting. 'Random Failures Are Often Concurrency Issues', # Tip #58, pg. 180 # Variations in timing and context can expose concurrency bugs, but in inconsistent and irreproducible ways. 'Use Actors For Concurrency Without Shared State', # Tip #59, pg. 182 # Use Actors to manage concurrent state without explicit synchronization. 'Use Blackboards to Coordinate Workflow', # Tip #60, pg. 189 # Use blackboards to coordinate disparate facts and agents, while maintaining independence and isolation among participants. 'Listen to Your Inner Lizard', # Tip #61, pg. 194 # When it feels like your code is pushing back, it’s really your subconscious trying to tell you something’s wrong. 'Don’t Program by Coincidence', # Tip #62, pg. 200 # Rely only on reliable things. Beware of accidental complexity, and don’t confuse a happy coincidence with a purposeful plan. 'Estimate the Order of Your Algorithms', # Tip #63, pg. 207 # Get a feel for how long things are likely to take before you write code. 'Test Your Estimates', # Tip #64, pg. 208 # Mathematical analysis of algorithms doesn’t tell you everything. Try timing your code in its target environment. 'Refactor Early, Refactor Often', # Tip #65, pg. 212 # Just as you might weed and rearrange a garden, rewrite, rework, and re-architect code when it needs it. Fix the root of the problem. 'Testing Is Not About Finding Bugs', # Tip #66, pg. 214 # A test is a perspective into your code, and gives you feedback about its design, api, and coupling. 'A Test Is the First User of Your Code', # Tip #67, pg. 216 # Use its feedback to guide what you do. 'Build End-To-End, Not Top-Down or Bottom Up', # Tip #68, pg. 218 # Build small pieces of end-to-end functionality, learning about the problem as you go. 'Design to Test', # Tip #69, pg. 221 # Start thinking about testing before you write a line of code. 'Test Your Software, or Your Users Will', # Tip #70, pg. 223 # Test ruthlessly. Don’t make your users find bugs for you. 'Use Property-Based Tests to Validate Your Assumptions', # Tip #71, pg. 224 # Property-based tests will try things you never thought to try, and exercise your code in ways is wasn’t meant to be used. 'Keep It Simple and Minimize Attack Surfaces', # Tip #72, pg. 234 # Complex code creates a breeding ground for bugs and opportunities for attackers to exploit. 'Apply Security Patches Quickly', # Tip #73, pg. 235 # Attackers deploy exploits as quick as they can, you have to be quicker. 'Name Well; Rename When Needed', # Tip #74, pg. 242 # Name to express your intent to readers, and rename as soon as that intent shifts. 'No One Knows Exactly What They Want', # Tip #75, pg. 244 # They might know a general direction, but they won’t know the twists and turns. 'Programmers Help People Understand What They Want', # Tip #76, pg. 245 # Software development is an act of co-creation between users and programmers. 'Requirements Are Learned in a Feedback Loop', # Tip #77, pg. 246 # Understanding requirements requires exploration and feedback, so the consequences of decisions can be used to refine the initial ideas. 'Work with a User to Think Like a User', # Tip #78, pg. 247 # It’s the best way to gain insight into how the system will really be used. 'Policy Is Metadata', # Tip #79, pg. 248 # Don’t hardcode policy into a system; instead express it as metadata used by the system. 'Use a Project Glossary', # Tip #80, pg. 251 # Create and maintain a single source of all the specific terms and vocabulary for a project. 'Don’t Think Outside the Box—Find the Box', # Tip #81, pg. 254 # When faced with an impossible problem, identify the real constraints. Ask yourself: “Does it have to be done this way? Does it have to be done at all?” "Don't Go into the Code Alone", # Tip #82, pg. 259 # Programming can be difficult and demanding. Take a friend with you. 'Agile Is Not a Noun; Agile Is How You Do Things', # Tip #83, pg. 259 # Agile is an adjective: it’s how you do something. 'Maintain Small Stable Teams', # Tip #84, pg. 264 # Teams should be small and stable, where everyone trusts each other and depends on each other. 'Schedule It to Make It Happen', # Tip #85, pg. 266 # If you don’t schedule it, it’s not going to happen. Schedule reflection, experimentation, learning and skills improvement. 'Organize Fully Functional Teams', # Tip #86, pg. 268 # Organize Around Functionality, Not Job Functions. Don’t separate UI/UX designers from coders, frontend from backend, testers from data modelers, design from deployment. Build teams so you can build code end-to-end, incrementally and iteratively. 'Do What Works, Not What’s Fashionable', # Tip #87, pg. 271 # Don’t adopt a development method or technique just because other companies are doing it. Adopt what works for your team, in your context. 'Deliver When Users Need It', # Tip #88, pg. 273 # Don’t wait weeks or months to deliver just because your process demands it. 'Use Version Control to Drive Builds, Tests, and Releases', # Tip #89, pg. 274 # Use commits or pushes to trigger builds, tests, releases. Use a version control tag to deploy to production. 'Test Early, Test Often, Test Automatically', # Tip #90, pg. 275 # Tests that run with every build are much more effective than test plans that sit on a shelf. 'Coding Ain’t Done ’Til All the Tests Run', # Tip #91, pg. 275 # ’Nuff said. 'Use Saboteurs to Test Your Testing', # Tip #92, pg. 277 # Introduce bugs on purpose in a separate copy of the source to verify that testing will catch them. 'Test State Coverage, Not Code Coverage', # Tip #93, pg. 278 # Identify and test significant program states. Testing just lines of code isn’t enough. 'Find Bugs Once', # Tip #94, pg. 278 # Once a human tester finds a bug, it should be the last time a human tester finds that bug. Automatic tests should check for it from then on. "Don't Use Manual Procedures", # Tip #95, pg. 279 # A computer will execute the same instructions, in the same order, time after time. "Delight Users, Don’t Just Deliver Code", # Tip #96, pg. 281 # Develop solutions that produce business value for your users and delight them every day. 'Sign Your Work', # Tip #97, pg. 282 # Artisans of an earlier age were proud to sign their work. You should be, too. 'First, Do No Harm', # Tip #98, pg. 286 # Failure is inevitable. Make sure no one will suffer because of it. 'Don’t Enable Scumbags', # Tip #99, pg. 287 # Because you risk becoming one, too. "It’s Your Life. Share it. Celebrate it. Build it. AND HAVE FUN!", # Tip #100, pg. 287: #Enjoy this amazing life we have, and do great things. ] today = bytes(datetime.datetime.today().strftime("%Y%m%d"), encoding='utf-8') idx = int(hashlib.sha1(today).hexdigest(), 16) % len(prag_tips) print( prag_tips[idx] )