What is Stack Overflow in JavaScript?
The concept of Stack Overflow was originally designed to prevent developers from posting large volumes of questions with poor formatting and low quality content.
It aims to create a community where programming questions are answered by developers that have a genuine interest in learning the answer.
However, Stack Overflow also serves as a sort of hub for developers looking for a new way to solve problems they have. Many problems that do not have a unique solution can be asked, answered and voted upon by users for others to reference. For example, a developer could ask a question like: What is the best way to load files with Ajax? or What is the best type of web storage?, which are fairly generic questions, but also have specific answers.
Stack Overflow is also a place where developers can provide guidance on their career paths. Most Stack Overflow users are professionals who have achieved a certain level of proficiency, and would not generally provide advice outside of their profession. However, the user base is still quite large, and many would find it helpful to receive feedback from fellow developers on how to achieve greater success in their profession.
Some examples of questions that can be asked on Stack Overflow are: Is it a good idea to use a 3rd party library like JQuery? What is the best language to learn first? What is the best approach for creating a web server? What is the best framework for creating a mobile app? What is the best method for managing user sessions? How do I properly handle user input? How can I reduce the chances of X happening? How can I improve the productivity of my team? These types of questions are all perfectly acceptable, and there are an infinite number of other questions that are equally valid. Each has a question and answer pair, and can be voted up and down.
What is the Stack Overflow in JavaScript Edition? There is a certain subset of questions that are just for JavaScript developers. These questions might be related to using JavaScript, or dealing with frameworks and libraries like jQuery or AngularJS. Questions about development environments like Node.js or Backbone.js also fit this category. Some examples of these questions include:
What is the best way to perform a task? How can I increase the speed of my application?
How to avoid Stack Overflow in JavaScript?
I am just an intermediate developer with no major programming experience.
One of my tasks is refactoring the JavaScript code in a page I work on. My boss assigned me this job because he had to get help from a professional web designer for that part.
So I wanted to improve the code quality, which is a good thing. I am quite good at my task, I just don't want to lose time trying to solve problems I can't really solve.
It's not very often I encounter Stack Overflow and I was wondering what is the best strategy for such situations. The most obvious solution for me would be to comment the code with "//TODO" or similar and come back later. But I was wondering if there was another approach that would better and faster.
I did read a lot about comments in JS here and there, but it seems that if I can find a way to avoid Stack Overflow (maybe with the use of some sort of flow control), it might be the better choice. What I came up with so far is this: There are 3 main blocks of code in that page (HTML, CSS and JS). I will assume there is not that much other code and it's pretty easy to spot the three.
My idea was to set a flag in each block of code to tell whether or not it's a "TODO" block. If it's a "TODO" block, I would add a couple of conditionals to make sure it's the last line of the code before it's closed.
So here is the code I wrote so far: This would obviously need a bit of work. I added an array to keep track of the state of each block and also some logic for closing each block before the end of the document.
I also added a "done" flag to all lines and set it to false if we are in a "TODO" block. I guess a more optimal version of the code is not the one I described above, but I hope I illustrated what I mean by avoiding Stack Overflow. Do you think I got the right idea? Or do you see any issues with the idea?
Why does JavaScript Stack Overflow?
We've all seen it before, haven't we?
Those two JavaScript lines that look like this: 1 2 3 4 5 6 7 8 var x = 1 ; function getX (). In almost every programming language, these two lines would be one big mess and the program wouldn't even compile. But in JavaScript, these two lines are perfectly valid. That's because JavaScript has no semicolons, so your function definition doesn't end there. You'll have to add a semi-colon at the end of the line yourself, just like this:
1 2 3 4 5 6 7 8 var x = 1 ; function getX () ;. So why does JavaScript let you do that? What is a semi-colon, anyway? Well, it's a semicolon. Semicolons are punctuation symbols. Like commas, periods, colons, semicolons, parentheses, braces, square brackets, curly braces, and brackets, semicolons are used to mark places where your code should end. They are called punctuation characters because they punctuate the statement or sentence.
So what do semicolons do? They mark the end of your statement. In this case, they mark the end of your function definition: 1 2 3 4 5 6 7 8 9 10 11 12 function getX (). The problem with doing this is that when your code compiles and gets sent to the server, your whole function will be sent back in a single line (it doesn't matter how long the function is), like this: 1 2 3 4 5 6 function getX (). This is bad because it messes up the browser's ability to display HTML correctly, because HTML ignores extra spaces and line breaks. So if the browser is sending back code like this, it might display your page like this:
.
What is Stack Overflow used for?
What if I can solve all my problems myself?
I have used this community before, and after my last question, I had to go in the chat. And there I was talking with a couple of the moderators, and asked what Stack Overflow is for. And some of you probably know what it is like when you got a question about C# and the answer was "use a compiler".
When I ask questions like these, I usually get answers telling me to use the compiler, or the IDE that comes with Visual Studio, or even the documentation from the programming language. So, my guess is that Stack Overflow is for finding out what the real answers are. It's not for people trying to explain how to program, but for people that already have the answer to their question, and just want to share that knowledge with others. They have been stuck, and they have answer to their problem, which they just can't find out for themselves, and they need help finding out how to do it, so they ask for help. That's why they ask questions. And that's why it's used to find out if you actually have the right solution to your problem.
But do you have to wait for years and years to get your question answered? How do people get their question answered in such a short time? A few ways. First of all, people who have been programming for long already know how to program. And that's great! It's great for the community because they have more knowledge than someone new. Also, they are more interested in improving the quality of Stack Overflow. And last but not least, it's just much better to write your question in a way that makes people read it without having to dig through every paragraph.
So, how does this work in practice? If someone wants to improve his or her code by using an article, like this one from Jon Skeet (who also writes for C#), and he can't find it, or maybe even can't find answer to his question on the internet, then he asks Stack Overflow. If he does the right thing, it's easier for someone else to answer that question, than to explain to him what to do in order to find that article, and to explain that answer in a way that he will understand it.