codete power search for developers stackoverflow tips tricks main 37ac19e2c2
Codete Blog

Power Search for Developers: StackOverflow Tips & Tricks

Radu Murzea c9226df606

19/07/2022 |

5 min read

Radu Murzea

Imagine this: you’re working on an awesome project, you’re deeply “in the zone” coding away in your favorite IDE, and you end up in a section where you need to connect to a PostgreSQL instance from your C# code. It shouldn’t be too hard, since it’s a fairly common programming task, but it’s been maybe a couple of years since the last time you wrote that exact piece of code.

You now have a choice: you can either try to figure it out on your own or find the snippet of code online and simply plug it into your project.

To save time, you’ll do what most programmers do: quickly open a new tab and search for “C# postgresql connect”.

StackOverflow’s SEO

There’s a very high chance that the results will redirect you to a StackOverflow question, as they are renowned for investing heavily in the most cutting-edge and effective SEO techniques.

However, if that’s not the case, you can go directly to stackoverflow.com and use their own search engine; one that is also quite advanced, as you’ll see below.

Most useful search operators

Just like Google’s search engine, there are various search operators that you can use, many of which are unique to StackOverflow:

1) Tags

Tags can be specified as “[tag1] [tag2]”. This way, you’ll get results only from questions that have those tags. Keep in mind that ] writing them like this, is equivalent to putting an “AND” between them.

A lesser-known variation of this is the use of the “OR” operator, as in  “[tag1] or [tag2]”, which does exactly what you’d expect. This can come in handy when you want to search for something that applies to multiple technologies but you only want to see the results of a few of them.

For example: “[mysql] or [postgresql] scheduled backups”.

2) Search within code blocks

This one is really useful if you remember bits of code but not the entire thing.

For example, let’s say you remember there was an answer somewhere with a piece of code that looks like this:

//language: C#

public void connectPostgreSQL()

{

    NpgsqlConnection connection = new NpgsqlConnection();

    connection = d_connection; // your connection string

    connection.Open();

    NpgsqlCommand cmd = new NpgsqlCommand();

    try {

        //execute query

    }

    catch (Exception e) { }

    finally {

        cmd.Dispose();

        connection.Dispose();

    }

}

A good way to find it again is simply to search using the “code” operator like so: “code:”NpgsqlConnection””

3) Search only popular questions

You can also specify whether the answer you’re looking for should only be found in popular questions. While they should theoretically appear at the top of the results, you can force this behavior by using the “views” operator.

For example: if you add “views:3000..1000000” to the search query, the results will only include questions that have between 3000 and 1 million views.

The “score” operator is another option fit for this purpose. By adding “score:20” , the results will only contain questions/answers with a score of 20 or higher.

4) Helpful Boolean Operators

There are various boolean operators that can be applied for further “fine-tuning” of search results. The most relevant are:

a) “isaccepted” – if you set this to true, only answers that are marked as accepted will be returned.

b) “hasaccepted” – very similar to “isaccepted”; the difference is that it applies to questions: if you set it to true, the results will contain only questions with an accepted answer.

c) “isanswered” – if set to true, it will return only questions that have at least one answer with a score of 1 or higher.

d) “closed” – setting this to “false”  is a good way to improve the quality of the results, given that closed questions are generally of lower quality.

Get to know the Platform

Did you know that StackOverflow isn’t the only site of its kind? It’s actually a subset of a much bigger platform called StackExchange. That platform contains an immense number of other websites, some of which are related to the programming/software domain:

If you can’t find the answer to your question on StackOverflow, maybe try your luck on one of the mentioned websites, especially if the domain of your search is more appropriately covered in one of them. For example: if you don’t want a piece of code, but instead you’re looking for a CLI command that will recursively search the entire contents of a directory for a piece of text, then maybe you might have a better chance of finding it on the Unix&Linux site.

Conclusion

Over its long and successful history, StackOverflow has become a vast repository of programming knowledge. And they also do a excellent  job of indexing that information, so that it’s easily accesible. There are, however, a few tricks that you can use to boost that “search satisfaction” to your advantage.

Rated: 5.0 / 3 opinions
Radu Murzea c9226df606

Radu Murzea

Backend PHP Developer at Codete with about 9 years of professional experience. Loves software engineering, but hates pineapple on pizza.

Our mission is to accelerate your growth through technology

Contact us

Codete Global
Spółka z ograniczoną odpowiedzialnością

Na Zjeździe 11
30-527 Kraków

NIP (VAT-ID): PL6762460401
REGON: 122745429
KRS: 0000983688

Get in Touch
  • icon facebook
  • icon linkedin
  • icon instagram
  • icon youtube
Offices
  • Kraków

    Na Zjeździe 11
    30-527 Kraków
    Poland

  • Lublin

    Wojciechowska 7E
    20-704 Lublin
    Poland

  • Berlin

    Bouchéstraße 12
    12435 Berlin
    Germany