ITHub

A 15 legjobb komment forráskódokból

A 15 legjobb komment forráskódokból
Kóbor Ádám
Kóbor Ádám
| ~5 perc olvasás

Kommentezni szép, kommentezni jó, kommentezni hasznos. Kivéve, ha egy adott megjegyzés nem a forráskód értelmezésére szolgál, hanem a fejlesztő aktuális hangulatának leképezése. Ebben az esetben viszont legalább nevetünk egy jót, amikor utólag belefutunk néhány gyöngyszembe. Válogatás következik önjelölt humoristák, és/vagy frusztrált programozók kommentjeiből.

legjobb kommentek forráskód

1. Rickrolling mesterfokon

/**
* For the brave souls who get this far: You are the chosen ones,
* the valiant knights of programming who toil away, without rest,
* fixing our most awful code. To you, true saviors, kings of men,
* I say this: never gonna give you up, never gonna let you down,
* never gonna run around and desert you. Never gonna make you cry,
* never gonna say goodbye. Never gonna tell a lie and hurt you.
*/

2. Használata sok esetben indokolt lehetne

// Dear maintainer:
// 
// Once you are done trying to 'optimize' this routine,
// and have realized what a terrible mistake that was,
// please increment the following counter as a warning
// to the next guy:
// 
// total_hours_wasted_here = 42
//

3. Vallási kérdés

//When I wrote this, only God and I understood what I was doing
//Now, God only knows

4. Nemmíszinnen!

// Autogenerated, do not edit. All changes will be undone.

5. Richard nem annyira népszerű a cégnél

namespace Mobile.Web.Control
{
    /// 
    /// Class used to work around Richard being a fucking idiot
    /// 
    /// 
    /// The point of this is to work around his poor design so that paging will 
    /// work on a mobile control. The main problem is the BindCompany() method, 
    /// which he hoped would be able to do everything. I hope he dies.
    /// 
    public abstract class RichardIsAFuckingIdiotControl : MobileBaseControl, ICompanyProfileControl
    {
        protected abstract Pager Pager { get; }

        public void BindCompany(int companyId) { }

        public RichardIsAFuckingIdiotControl()
        {
            MakeSureNobodyAccidentallyGetsBittenByRichardsStupidity();
        }

        private void MakeSureNobodyAccidentallyGetsBittenByRichardsStupidity()
        {
            // Make sure nobody is actually using that fucking bindcompany method
            MethodInfo m = this.GetType().GetMethod("BindCompany", BindingFlags.DeclaredOnly | 
                BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            if (m != null)
            {
                throw new RichardIsAFuckingIdiotException("No!! Don't use the fucking BindCompany method!!!");
            }
            // P.S. this method is a joke ... the rest of the class is fucking serious
        }

        /// 
        /// This returns true if this control is supposed to be doing anything
        /// at all for this request. Richard thought it was a good idea to load
        /// the entire website during every request and have things turn themselves
        /// off. He also thought bandanas and aviator sunglasses were "fuckin' 
        /// gnarly, dude."
        /// 
        protected bool IsThisTheRightPageImNotSureBecauseRichardIsDumb()
        {
            return Request.QueryString["Section"] == this.MenuItemKey;
        }

        protected override void OnLoad(EventArgs e)
        {
            if (IsThisTheRightPageImNotSureBecauseRichardIsDumb())
            {
                Page.LoadComplete += new EventHandler(Page_LoadComplete);
                Pager.RowCount = GetRowCountBecauseRichardIsDumb();
            }
            base.OnLoad(e);
        }

        protected abstract int GetRowCountBecauseRichardIsDumb();
        protected abstract void BindDataBecauseRichardIsDumb();

        void Page_LoadComplete(object sender, EventArgs e)
        {
            BindDataBecauseRichardIsDumb();
        }

        // the rest of his reduh-ndant interface members
        public abstract string MenuItemName { get; set; }
        public abstract string MenuItemKey { get; set; }
        public abstract bool IsCapable(CapabilityCheck checker, int companyId);
        public abstract bool ShowInMenu { get; }
        public virtual Control CreateHeaderControl()
        {
            return null;
        }
    }
}

6. Őszinte

// drunk, fix later

7. Mindenki varázsol néha a karrierje során

// Magic. Do not touch.

8. A félreértések elkerülése végett

return 1; // returns 1

9. Megmagyarázza

/* This is O(scary), but seems quick enough in practice. */

10. Irónia level 9999

try {

} finally { // should never happen 

}

11. A meg nem értett művész

# Christmas tree initializer  
    toConnect = []  
    toRead =   [  ]  
    toWrite = [    ]   
    primes = [      ]  
    responses = {}  
    remaining = {}

12. Nézőpont kérdése

/////////////////////////////////////// this is a well commented line

13. A gravitáció manipulálására mostanában úgyis nagy igény mutatkozik idehaza

// I don't know why I need this, but it stops the people being upside-down
x = -x;

14. Azt bárki mondhassa!

// I am not responsible of this code.
// They made me write it, against my will.

15. Hirtelen felindulásból elkövetett kommentelés

// no comments for you
// it was hard to write
// so it should be hard to read

Forrás: stackoverflow

Nektek mi volt a legviccesebb kommentetek, amivel találkoztatok? Mondjátok el!