Share E-Book

Street Coder The rules to break and how to break them (Final Release) (Sedat Kapanoglu) (z-library.sk, 1lib.sk, z-lib.sk)

Author

Rating 4.0 AI initial rating

Log in to rate

Code
Language English

Street Coder: Rules to break and how to break them is a programmer's survival guide, full of tips, tricks, and hacks that will make you a more efficient programmer. Software development isn't an "ivory tower" exercise. Street coders get the job done by prioritizing tasks, making quick decisions, and knowing which rules to break. Street Coder: Rules to break and how to break them is a programmer's survival guide, full of tips, tricks, and hacks that will make you a more efficient programmer. This book's rebel mindset challenges status quo thinking and exposes the important skills you need on the job. You'll learn the crucial importance of algorithms and data structures, turn programming chores into programming pleasures, and shatter dogmatic principles keeping you from your full potential. Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

Format PDF
Size 8.8 MB
(First 20 pages)

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Page 1
M A N N I N G Sedat Kapanoglu The rules to break and how to break them With examples in C# ˘
Page 2
Impact of complexity on performance Search algorithm Complexity Time to find a record among 60 rows The DIY quantum computer Lisa’s uncle has in his garage O(1) 1 second Binary search O(log N) 6 seconds Linear search (because your boss asked you to do it an hour before the presentation) O(N) 60 seconds The intern accidentally nested two for loops. O(N2) 1 hour Some randomly pasted code from Stack Overflow that also finds a solution to some chess problem while searching, but the developer didn’t bother to remove that part. O(2N) 36.5 billion years Instead of finding the actual record, the algorithm tries to find the arrangement of records that spell out the record you’re looking for when sorted in a certain way. The good news is that the developer doesn’t work here anymore. O(N!) The end of the universe, but still before those monkeys finish their so-called Shakespeare
Page 3
Street Coder THE RULES TO BREAK AND HOW TO BREAK THEM SEDAT KAPANOĞLU M A N N I N G SHELTER ISLAND
Page 4
For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Email: orders@manning.com ©2022 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. The author and publisher have made every effort to ensure that the information in this book was correct at press time. The author and publisher do not assume and hereby disclaim any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from negligence, accident, or any other cause, or from any usage of the information herein. Manning Publications Co. Development editors: Toni Arritola and Becky Whitney 20 Baldwin Road Technical development editor: Frances Buontempo PO Box 761 Review editor: Aleksandar Dragosavljević Shelter Island, NY 11964 Production editor: Keri Hales Copy editor: Suzanne G. Fox Proofreader: Katie Tennant Technical proofreader: Orlando Méndez Morales Typesetter: Gordan Salinovic Cover designer: Marija Tudor ISBN 9781617298370 Printed in the United States of America
Page 5
To my brother Muzaffer, who introduced me to the fantastic world of computers
Page 6
(This page has no text content)
Page 7
v brief contents 1 ■ To the streets 1 2 ■ Practical theory 14 3 ■ Useful anti-patterns 53 4 ■ Tasty testing 94 5 ■ Rewarding refactoring 122 6 ■ Security by scrutiny 140 7 ■ Opinionated optimization 171 8 ■ Palatable scalability 198 9 ■ Living with bugs 222
Page 8
(This page has no text content)
Page 9
vii contents preface xiii acknowledgments xv about this book xvii about the author xx about the cover illustration xxi 1 To the streets 1 1.1 What matters in the streets 2 1.2 Who’s a street coder? 3 1.3 Great street coders 4 Questioning 5 ■ Results-driven 5 ■ High-throughput 6 Embracing complexity and ambiguity 6 1.4 The problems of modern software development 7 Too many technologies 8 ■ Paragliding on paradigms 9 The black boxes of technology 10 ■ Underestimating overhead 11 ■ Not my job 11 ■ Menial is genial 11 1.5 What this book isn’t 12 1.6 Themes 12
Page 10
CONTENTSviii 2 Practical theory 14 2.1 A crash course on algorithms 15 Big-O better be good 17 2.2 Inside data structures 19 String 20 ■ Array 23 ■ List 24 ■ Linked list 25 Queue 26 ■ Dictionary 26 ■ HashSet 29 ■ Stack 29 Call stack 30 2.3 What’s the hype on types? 30 Being strong on the type 31 ■ Proof of validity 32 ■ Don’t framework hard, framework smart 37 ■ Types over typos 40 To be nullable or non-nullable 41 ■ Better performance for free 47 ■ Reference types vs. value types 49 3 Useful anti-patterns 53 3.1 If it ain’t broke, break it 54 Facing code rigidity 54 ■ Move fast, break things 55 Respecting boundaries 56 ■ Isolating common functionality 57 Example web page 59 ■ Leave no debt behind 60 3.2 Write it from scratch 61 Erase and rewrite 61 3.3 Fix it, even if it ain’t broke 62 Race toward the future 62 ■ Cleanliness is next to codeliness 64 3.4 Do repeat yourself 66 Reuse or copy? 70 3.5 Invent it here 71 3.6 Don’t use inheritance 74 3.7 Don’t use classes 76 Enum is yum! 76 ■ Structs rock! 78 3.8 Write bad code 83 Don’t use If/Else 83 ■ Use goto 85 3.9 Don’t write code comments 88 Choose great names 90 ■ Leverage functions 90
Page 11
CONTENTS ix 4 Tasty testing 94 4.1 Types of tests 95 Manual testing 95 ■ Automated tests 96 ■ Living dangerously: Testing in production 96 ■ Choosing the right testing methodology 97 4.2 How to stop worrying and love the tests 99 4.3 Don’t use TDD or other acronyms 105 4.4 Write tests for your own good 106 4.5 Deciding what to test 107 Respect boundaries 107 ■ Code coverage 110 4.6 Don’t write tests 112 Don’t write code 112 ■ Don’t write all the tests 112 4.7 Let the compiler test your code 113 Eliminate null checks 113 ■ Eliminate range checks 116 Eliminate valid value checks 118 4.8 Naming tests 120 5 Rewarding refactoring 122 5.1 Why do we refactor? 123 5.2 Architectural changes 124 Identify the components 126 ■ Estimate the work and the risk 127 ■ The prestige 128 ■ Refactor to make refactoring easier 129 ■ The final stretch 135 5.3 Reliable refactoring 136 5.4 When not to refactor 138 6 Security by scrutiny 140 6.1 Beyond hackers 141 6.2 Threat modeling 142 Pocket-sized threat models 144 6.3 Write secure web apps 146 Design with security in mind 146 ■ Usefulness of security by obscurity 147 ■ Don’t implement your own security 148 SQL injection attacks 149 ■ Cross-site scripting 155 Cross-site request forgery 159
Page 12
CONTENTSx 6.4 Draw the first flood 161 Don’t use captcha 161 ■ Captcha alternatives 162 Don’t implement a cache 162 6.5 Storing secrets 163 Keeping secrets in source code 163 7 Opinionated optimization 171 7.1 Solve the right problem 172 Simple benchmarking 172 ■ Performance vs. responsiveness 175 7.2 Anatomy of sluggishness 177 7.3 Start from the top 178 Nested loops 179 ■ String-oriented programming 181 Evaluating 2b || !2b 182 7.4 Breaking the bottle at the neck 183 Don’t pack data 183 ■ Shop local 185 ■ Keep dependent works separated 185 ■ Be predictable 187 ■ SIMD 189 7.5 1s and 0s of I/O 191 Make I/O faster 191 ■ Make I/O non-blocking 193 The archaic ways 194 ■ Modern async/await 195 Gotchas of async I/O 196 7.6 If all else fails, cache 196 8 Palatable scalability 198 8.1 Don’t use locks 199 Double-checked locking 206 8.2 Embrace inconsistency 209 The dreaded NOLOCK 209 8.3 Don’t cache database connections 211 In the form of an ORM 214 8.4 Don’t use threads 215 The gotchas of async code 219 ■ MULTITHREADING with async 219 8.5 Respect the monolith 220
Page 13
CONTENTS xi 9 Living with bugs 222 9.1 Don’t fix bugs 223 9.2 The error terror 224 The bare truth of exceptions 225 ■ Don’t catch exceptions 227 Exception resiliency 229 ■ Resiliency without transactions 233 Exceptions vs. errors 234 9.3 Don’t debug 236 printf() debugging 236 ■ Dump diving 237 ■ Advanced rubber-duck debugging 240 index 243
Page 14
(This page has no text content)
Page 15
xiii preface I’ve experienced many distinct aspects of becoming proficient in software develop- ment as a self-taught programmer (other than reading books), ranging from trying to learn machine language by putting random numbers in memory and observing whether the results were anything other than a simple halt, to spending nights in smoke-filled offices, to sneaking off the university campus in the middle of the night after working clandestinely in the lab as a high schooler, to reading the contents of binary files and just hoping that getting exposed to some bytes would make me magi- cally understand how the code works, to memorizing opcodes, and to trying every combination of the order of arguments to figure out the correct one in a function due to lack of documentation. Back in 2013, my friend Aziz Kedi, who used to own a bookstore in Istanbul, asked me to write a book about software development based on my experiences. That was the first time I considered writing a book about my profession. I had to shelve the idea soon thereafter because Aziz closed his bookstore and moved to London. I kept entertaining the idea of having a book I could hand out to new team mem- bers who were at the start of their career so they could close the experience gap while widening their perspective. The pre-career understanding of software development is heavily shaped by curricula, preconceptions, and best practices. A newly minted pro- grammer naturally thinks of their accumulated knowledge as a core investment and doesn’t want to wander far from it. At some point, I decided to write such a book—very slowly. I called the fictional book Street Coder and started making notes of random ideas that could make the lives
Page 16
PREFACExiv of new developers easier. They didn’t have to be best practices, either—they could even be bad practices, if you will, as long as they made developers better thinkers about the problems they faced. The document had grown, and at a certain point, I forgot about it, until the day I got a call from London. It wasn’t Aziz Kedi this time. He was probably busy writing screenplays back then, and I’m sure he’s working on another one as I’m writing this. This time, it was Andy Waldron from Manning Publications. He asked me, “What idea do you have for a book?” I couldn’t think of anything at first, and I was preparing—just to gain some time—to counter his question with this question: “Well, what did you have in mind?” I pretty much mumbled a bit, and then it suddenly struck me. I remembered the notes I’d been taking and the title I had given it: Street Coder. The title comes from what I learned in the streets, the professional software devel- opment world, by many trials and errors, which gave me a pragmatic, down-to-earth perspective about approaching software development as a craft. This book conveys the changes in perspective I’ve experienced so you’ll have a head start in your career.
Page 17
xv acknowledgments This book wouldn’t have been possible without my wife, Günyüz. She’s carried every- thing on her shoulders while I’ve been busy writing. Thank you, babe. I love you. Thanks go to Andrew Waldron, who kick-started my passion for authoring this book. This has been a phenomenal experience. Andy has always been tolerant and understanding, even when I accused him of secretly sneaking into my home and changing the book’s text. I owe you a drink, Andy. Thanks go to my development editors, Toni Arritola, who taught me everything I know about writing programming books, and Becky Whitney, who’s been patient and good natured about all the badly written parts I originally turned in—which were Andy’s doing, really. Thanks go to the technical reviewer, Frances Buontempo, who’s been extremely constructive and on-point for the technical feedback. Thanks also go to Orlando Mén- dez Morales for making sure that the code I share in the book actually makes sense. Thanks go to my friends Murat Girgin and Volkan Sevim, who reviewed the earliest drafts and assured me that my jokes would’ve been funny if the reader knew me. I thank Donald Knuth for letting me quote him. I find myself lucky to have gotten a personal response from him, even if it was only “OK.” I also thank Fred Brooks for reminding me that there’s a fair use clause in the copyright law, so I don’t need to call him every day to ask for his permission, and also not to trespass in his home at 3 a.m. There was really no need to involve the cops, Fred—I was just leaving! Thanks also go to Leon Bambrick for letting me quote him peacefully.
Page 18
ACKNOWLEDGMENTSxvi Thanks go to MEAP readers, especially Cihat İmamoğlu, whom I don’t know per- sonally, but who wrote a crazy amount of in-depth feedback. I thank all the Manning reviewers: Adail Retamal, Alain Couniot, Andreas Schabus, Brent Honadel, Cameron Presley, Deniz Vehbi, Gavin Baumanis, Geert Van Laethem, Ilya Sakayev, Janek López Romaniv, Jeremy Chen, Jonny Nisbet, Joseph Perenia, Karthikeyarajan Rajendran, Kumar Unnikrishnan, Marcin Sęk, Max Sadrieh, Michael Rybintsev, Oliver Korten, Onofrei George, Orlando Méndez Morales, Robert Wilk, Samuel Bosch, Sebastian Felling, Tiklu Ganguly, Vincent Delcoigne, and Xu Yang—your suggestions helped make this a better book. And finally, I thank my dad for teaching me that I can make my own toys.
Page 19
xvii about this book Street Coder fills in the gaps of the professional experience of a software developer by tackling well-known paradigms, showing anti-patterns, and seemingly bad or less- known practices that can be useful in the streets—the professional world. The goal of the book is to equip you with a questioning and practical mindset and to help you understand that the cost of creating software is more than just Googling and typing. It also shows that some mundane work can help you save more time than it takes. In general, the book aims to be a perspective changer. Who should read this book This book is for beginning- and medium-level programmers who have managed to learn programming by means other than traditional schooling, but who still need an expanded perspective on paradigms and best practices of software development. The examples are in C# and .NET, so familiarity with those languages can help as you read, but the book strives to be, as much as possible, language and framework agnostic. How this book is organized: A road map ■ Chapter 1 introduces the concept of a street coder—a developer who has been molded by professional experience—and describes the qualities that can help you become that person. ■ Chapter 2 discusses how theory matters in practical software development and why you should care about data structures and algorithms.
Page 20
ABOUT THIS BOOKxviii ■ Chapter 3 explains how certain anti-patterns or bad practices can actually be useful or even be preferable in many situations. ■ Chapter 4 tackles the mysterious world of unit testing and how it can help you write less code and do less work, even though it may seem to be more work initially. ■ Chapter 5 discusses techniques for refactoring, how to do it easily and safely, and when to avoid it. ■ Chapter 6 introduces some basic security concepts and techniques and shows defenses against most common attacks. ■ Chapter 7 shows some hard-core optimization techniques, shamelessly recom- mends premature optimization, and describes a methodical approach to fixing performance problems. ■ Chapter 8 describes techniques to make your code more scalable and tackles par- allelization mechanics and their impact on performance and responsiveness. ■ Chapter 9 goes over best practices for handling bugs and errors. Specifically, it encourages not handling errors and describes techniques for writing fault- resilient code. About the code Most of the code is included to support concepts and may be missing implementation details to focus on the actual topic. Fully functioning code has been provided for several projects in the online GitHub repository (https://github.com/ssg/streetcoder) and on the Manning website (https://www.manning.com/books/street-coder), so you can run them and experiment on them locally. One example specifically focuses on a migration scenario from .NET Framework, which means that specific project may not build on non-Windows machines. An alternate solution file for the book is provided in the repos- itory for those platforms so you can build without any issues. This book contains many examples of source code both in numbered listings and in line with normal text. In both cases, source code is formatted in a fixed-width font like this to separate it from ordinary text. Sometimes code is also in bold to highlight code that has changed from previous steps in the chapter, such as when a new feature adds to an existing line of code. In many cases, the original source code has been reformatted; we’ve added line breaks and reworked indentation to accommodate the available page space in the book. In rare cases, even this was not enough, and listings include line-continuation markers (➥). Additionally, comments in the source code have often been removed from the listings when the code is described in the text. Code annotations accompany many of the listings, highlighting important concepts. liveBook discussion forum Purchase of Street Coder includes free access to liveBook, Manning’s online reading plat- form. Using liveBook’s exclusive discussion features, you can attach comments to the
The above is a preview of the first 20 pages. Register to read the complete e-book.

Recommended for You

Loading recommended books...
Failed to load, please try again later

Tip the Site

Scan the WeChat Pay or Alipay code to tip. No login required.

WeChat Pay
Alipay

Every 10 yuan is 1 year of VIP; the remainder counts as months (5 yuan is 5 months, 100 yuan is 10 years). Signed-in users are enabled immediately and both you and the admin get an email. Guests receive an ID and are sent to register.

← Back to List