baavgai's Profile User Rating: *****

Reputation: 5800 Overlord
Active Posts:
12,637 (5.04 per day)
16-October 07
Profile Views:
Last Active:
User is offline Today, 06:46 AM

Previous Fields

OS Preference:
Favorite Browser:
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Your Car:
Who Cares
Dream Kudos:
Expert In:
C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

Latest Visitors

Icon   baavgai has not set their status

Posts I've Made

  1. In Topic: [HELP] SQL Query

    Posted 28 Aug 2014

    Ok, the where x=(subquery) thing is very, very bad. You're completely trusting that you will get one and only one result from the subquery. It's also extra slow in most cases.

    First, let's layout what you have:
    SELECT *
        FROM `backorder_list`
        WHERE `PurchaseDetailsID`= (
            SELECT PurchaseDetailsID
                FROM `purchase_details`
                WHERE ProductID=(
                    SELECT ProductID FROM Product WHERE ProductName LIKE 'O%'

    Your inner most query is where we look first:
    SELECT p.ProductID
        FROM Product p
        WHERE p.ProductName LIKE 'O%'

    Ok, that's fine. Now, let's expand it to the next level:
    SELECT p.ProductID, pd.PurchaseDetailsID
        FROM Product p
        INNER JOIN `purchase_details` pd
            ON p.ProductID=pd.ProductID
        WHERE p.ProductName LIKE 'O%'

    There, now you have your two tables joined together. This configuration will be used a lot for any query against details.

    Now, the final level:
    SELECT bo.*
        FROM Product p
        INNER JOIN `purchase_details` pd
            ON p.ProductID=pd.ProductID
        INNER JOIN `backorder_list` bo
            ON bo.PurchaseDetailsID=pd.PurchaseDetailsID
        WHERE p.ProductName LIKE 'O%'

    Hope this helps.
  2. In Topic: Reusing similar search queries for different arrays

    Posted 27 Aug 2014

    Remove your SQL Injection waiting to happen: nid='{$arg[1]}'. Use

    Depending on the DB engine, that will speed things up.

    To the select, why not both at once?
      (case when status='ok' then 'Y' else 'N' end) as is_ok,
      DATE_FORMAT(sent, '%Y%m') as dt,
      COUNT(id) as cid
    FROM sendlog
    WHERE nid=?
       AND PERIOD_DIFF( date_format(now(), '%Y%m'), date_format(sent, '%Y%m') ) < 8
    GROUP BY YEAR(sent),MONTH(sent), (case when status='ok' then 'Y" else 'N' end)

    Actually, you could throw them on the same line, if you're just after count:
      DATE_FORMAT(sent, '%Y%m') as dt,
      sum(case when status='ok' then 1 else 0 end) as is_ok_cid,
      sum(case when status='ok' then 0 else 1 end) as is_not_ok_cid
    FROM sendlog
    WHERE nid=?
       AND PERIOD_DIFF( date_format(now(), '%Y%m'), date_format(sent, '%Y%m') ) < 8
    GROUP BY DATE_FORMAT(sent, '%Y%m')

    Hope this helps.
  3. In Topic: Logger static class thread safety

    Posted 26 Aug 2014

    Hmm... Just for fun, and to show the event idea being described.

    public static class Logger {
        public delegate void MessageHandler(DateTime sendDt, string message);
        public static event MessageHandler MessageAdded;
        public static void SendMessage(string message) {
            if (MessageAdded != null) { MessageAdded(DateTime.Now, message); }

    Yes, that's actually a complete class.

    You'd use it by adding event listeners and then calling. For instance, to see a dump on the screen:
    Logger.MessageAdded += (dt, msg) => { Console.WriteLine(dt + ": " + msg); };

    Here's a quick tester program:
    class Program {
        private static void Spam(string stub) {
            System.Threading.Tasks.Task.Run(() => {
                for (int i = 0; i < 10000; i++) {
                    Logger.SendMessage(stub + " " + i++);
        static void Main(string[] args) {
            Logger.MessageAdded += (dt, msg) => { Console.WriteLine(dt + ": " + msg); };
            var writer = System.IO.File.AppendText("dump.log");
            Logger.MessageAdded += (dt, msg) => { writer.WriteLine(dt + ": " + msg); writer.Flush(); };
            // Logger.MessageAdded += (dt, msg) => { System.Diagnostics.Debug.WriteLine(dt + ": " + msg); };

    This is fun, as you'll see the non blocking nature of how this is spinning. That said, look into how logging is already done before you roll your own. However, if you understand some of the concepts here, you should be in a better place write your own logger in the future; which might be useful for a smaller project.

    Hope this helps.
  4. In Topic: Why is Java so circuitous and tortuous compared to C/C++?

    Posted 25 Aug 2014

    View Postneedycoder, on 25 August 2014 - 10:52 AM, said:


    It's not so straight forward or convenient in Java.

    What is i? I can't tell from your snippet. That's not terribly straight forward. Do you know the code that's actually being called with that statement? It's probably more circuitous than you know.

    int i = input.nextInt();

    Here, I understand I'm calling a method that belongs to input and returns int. Again, not particularly torturous, but potentially clearer.

    If you want a terse language, try Haskell; Java will generally fail you on the brevity of statement front. It's worth noting that anything serious in C++ will also get rather verbose. The ubiquitous cin is a cherry picked example. Try iterating over a vector prior to C++x.
  5. In Topic: Why is Java so circuitous and tortuous compared to C/C++?

    Posted 25 Aug 2014

    cin is an interesting example. First, it's only partial: you want std::cin. If you go down the rabbit hole of what drives that, it's a huge, messy, tangle of fake_istream and aliases, and so on. To get that "simple" cin to work, every type must be aware of istream and write an operator override to accommodate it. Note, that cin is an instance of istream that points to stdin...

    Back to Java. Java disallows multiple inheritance and forces class based implementation. So, for an instance that talks to stdin, or, you logically must create that instance. Note, Scanner is just to darling of the moment; older java programs preferred other wrappers for their

    So, you have a program and you chuck in a line like:
    private final Scanner kbIn = new Scanner(; 

    And use that consistently in the instance. This approach is consistent with how everything else in java works. It doesn't seem to be a huge hardship to do.

    I'd love to see a realistic program in both C++ and Java where you feel Java is more "circuitous and tortuous" than C++. Simply stating it doesn't prove the assertion.

My Information

Member Title:
Dreaming Coder
Age Unknown
Birthday Unknown
Jersey, be afraid.
Years Programming:
Programming Languages:

Contact Information

Click here to e-mail me
Website URL:
Website URL  http://


  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  1. Photo

    8byte Icon

    10 Jan 2014 - 11:08
    Awesome, thanks for all the help!
  2. Photo

    codiddle Icon

    07 Mar 2013 - 18:59
    GENIUS GUY HERE MAN. Write a book!
  3. Photo

    mamelove25 Icon

    19 Feb 2013 - 10:53
    Hello My Dear, My Name is Mame. i saw your profile today and became interested in you,i will also like to know you more,and if you can send an email to my email address,i will give you my pictures here is my email address ( I believe we can move from here! Am waiting for your mail to my email address above because i have much to tell you,
    love Miss Mame.
  4. Photo

    bilbil0629 Icon

    24 Oct 2012 - 05:39
    hey! you mongolian?
  5. Photo

    Ticon Icon

    20 Aug 2012 - 13:23
    I just noticed your an expert in cheese. I lol'd
  6. Photo

    mostyfriedman Icon

    18 Aug 2012 - 23:13
    Hello there Brett
  7. Photo

    MehrdadSecret Icon

    26 Jul 2012 - 05:51
    hello, can i have a contact email or Yahoo or something? Need ur help badly
  8. Photo Icon

    18 Apr 2012 - 23:17
    Thanks ! Solved My problem !
  9. Photo

    RetardedGenius Icon

    25 Oct 2011 - 14:29
    I agree so much with your opinion of incompetent CS teachers. So true!
  10. Photo

    WabiSabi Icon

    21 Oct 2011 - 11:00
    I agree with assert(C). However, I'd rather not specify what you are "the best" at.
  11. Photo

    assert(C) Icon

    20 Oct 2011 - 08:38
    You are the best
  12. Photo

    macosxnerd101 Icon

    30 Sep 2011 - 09:33
    Congrats on hitting the big 3k!
  13. Photo

    sjin Icon

    16 Aug 2011 - 18:41
    This guy is AWESOME! Cheers bro!
  14. Photo

    hulla Icon

    02 Aug 2011 - 02:50
    Wow that's alot of programming languages... :O
  15. Photo

    Aphex19 Icon

    04 Jul 2011 - 16:54
    Kudos to you baavgai, the most well deserved mentor on DIC in my opinion.
  • (3 Pages)
  • +
  • 1
  • 2
  • 3