What anti-patterns exist for JavaScript? [closed]

Language: Namespace polluting by creating a large footprint of variables in the global context. Binding event handlers in the form ‘foo.onclick = myFunc’ (inextensible, should be using attachEvent/addEventListener). Using eval in almost any non-JSON context Almost every use of document.write (use the DOM methods like document.createElement) Prototyping against the Object object (BOOM!) A small one … Read more

Singleton in go

Setting aside the argument of whether or not implementing the singleton pattern is a good idea, here’s a possible implementation: package singleton type single struct { O interface{}; } var instantiated *single = nil func New() *single { if instantiated == nil { instantiated = new(single); } return instantiated; } single and instantiated are private, … 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

What is the most EVIL code you have ever seen in a production enterprise environment? [closed]

Warning: Long scary post ahead I’ve written about one application I’ve worked on before here and here. To put it simply, my company inherited 130,000 lines of garbage from India. The application was written in C#; it was a teller app, the same kind of software tellers use behind the counter whenever you go to … 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

Why is Singleton considered an anti-pattern? [duplicate]

To help with answering, here is more about the anti-pattern comment: it is overused, introduces unnecessary restrictions in situations where a sole instance of a class is not actually required, and introduces global state into an application From: http://en.wikipedia.org/wiki/Singleton_pattern For more on this you can look at: https://www.michaelsafyan.com/tech/design/patterns/singleton Here is a great ending to the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)