What is an anti-pattern?

Anti-patterns are certain patterns in software development that are considered bad programming practices. As opposed to design patterns which are common approaches to common problems which have been formalized and are generally considered a good development practice, anti-patterns are the opposite and are undesirable. For example, in object-oriented programming, the idea is to separate the … Read more

Python: is using “..%(var)s..” % locals() a good practice?

It’s OK for small applications and allegedly “one-off” scripts, especially with the vars enhancement mentioned by @kaizer.se and the .format version mentioned by @RedGlyph. However, for large applications with a long maintenance life and many maintainers this practice can lead to maintenance headaches, and I think that’s where @S.Lott’s answer is coming from. Let me … Read more

Counting lines or enumerating line numbers so I can loop over them – why is this an anti-pattern?

The shell (and basically every programming language which is above assembly language) already knows how to loop over the lines in a file; it does not need to know how many lines there will be to fetch the next one — strikingly, in your example, sed already does this, so if the shell couldn’t do … Read more

How to block users from closing a window in Javascript?

Take a look at onBeforeUnload. It wont force someone to stay but it will prompt them asking them whether they really want to leave, which is probably the best cross browser solution you can manage. (Similar to this site if you attempt to leave mid-answer.) <script language=”JavaScript”> window.onbeforeunload = confirmExit; function confirmExit() { return “You … Read more

tech