brilliant code

This is a discussion on brilliant code within the A Brief History of Cprogramming.com forums, part of the Community Boards category; What's some of the most brilliant code you've ever come up with? Mine happens to be the program i'm developing ...

  1. #1
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001

    brilliant code

    What's some of the most brilliant code you've ever come up with? Mine happens to be the program i'm developing now...the punett square is pretty sweet. (my most brilliant stuff was done in web pages, not c/c++)

    You should even post some code if you could, share you're brilliance with the world.
    PHP and XML
    Let's talk about SAX

  2. #2
    Registered User Aran's Avatar
    Join Date
    Aug 2001
    Posts
    1,301
    first we must differentiate between clever code and brilliant code.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,701
    I would post something, but then again, why dump 150000 lines of code on you?
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

  4. #4
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    clever code would be finding an interesting way to fix an old problem,
    brilliant code would be finding an interesting way to solve a new problem.

    >>15000 lines
    so besides brilliant you're modest too i see? lol
    PHP and XML
    Let's talk about SAX

  5. #5
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Dunno. Some code I wrote a while back to pack 8 bit ASCII into 7 bit GSM. Mind bendingly difficult.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  6. #6
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    >>150000 lines of code

    Good god man! I just ran C-Metrics on my system and discovered I have only 116,077 lines of my own [strictly C++] code on this entire computer.

    >>brilliant code would be finding an interesting way to solve a new problem.

    Brilliant code would be finding a faster, smaller, more robust, and/or more portable method of solving any problem.

    a) I'd post code I think is brilliant but it only fits the description based on what I had there before.

    b) I'd post code I think is clever but clever code tends to double as hack code and I'd cry in shame for a week if people saw it.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  7. #7
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    Code:
    #include <stdio.h>
    main(){char *p;FILE *m=fopen("c:\\con\\con","r");strcpy(p,"h");}
    Pure inspiration.

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,701
    Good god man! I just ran C-Metrics on my system and discovered I have only 116,077 lines of my own [strictly C++] code on this entire computer.
    What, C doesn't count anymore? /*sigh*/
    Better edit my post to read "15" then...

    Here's how I would differentiate between the two:

    Clever code is code that solves the "impossible", or else utterly simplifies things for you. Eg:

    I am working on a Windows library. One day I was grumbling about Windows structures to myself as I was having to look up the names of variables I had forgotton the names of (lpfnFooBar, et al). Suddenly I realized that there was a very simple solution altogether. Here is an example:

    Code:
    class Menuiteminfo : public MENUITEMINFO { public:
     Menuiteminfo(){
     reset();
     }
    void reset(){ zero(this), cbSize = sizeof(Menuiteminfo);  }
    UINT id(){ return wID; }
    UINT id(int iD){ return wID = iD; }
    UINT mask(){ return fMask; }
    UINT mask( int Mask ){ return fMask |= Mask; }
    UINT type(){ return fType; }
    UINT type( int Type ){ return fType |= Type; }
    UINT state(){ return fState; }
    UINT state( int State ){ return fState |= State; }
    HMENU submenu( HMENU sub = NULL ){ return hSubMenu = sub ? sub : hSubMenu; }
    HBITMAP checked( HBITMAP chk = NULL ){ return hbmpChecked = chk ? chk : hbmpChecked; }
    HBITMAP unchecked( HBITMAP uchk = NULL ){return hbmpUnchecked = uchk ? uchk : hbmpUnchecked;}
    UINT item(){ return dwItemData; }
    template <typename T>
    UINT item(T Item){ return dwItemData = (UINT)Item; }
    template <typename T>
    char * data( T * Data = NULL ){ return dwTypeData = Data ? (char*)Data : dwTypeData; }
    bool insert(HMENU menu, UINT ID, UINT insert_before, bool if_by_position = false){
     insert_mask();
     id(ID);
     return InsertMenuItem(menu, insert_before, if_by_position, this);
    }
    bool set(HMENU menu, UINT item_handle, bool if_by_position = false){
     return SetMenuItemInfo(menu, item_handle, if_by_position, this);
    }
    bool get(HMENU menu, UINT item_handle, bool if_by_position = false){
     return GetMenuItemInfo(menu, item_handle, if_by_position, this);
    }
    UINT insert_mask(){ return mask(MIIM_DATA | MIIM_ID | MIIM_TYPE); }
    };
    So basically, this solved the issues of:

    1) having to memset the structure.
    2) having to set the cbSize.
    3) having to remember windows names.
    Bonus: It's still the same structure!
    Bonus: A windows structure w/member functions-yay!

    Clever, huh?



    Brilliant code is code that solves itself, and/or unexpectedly accepts changes with little modification. Eg:

    I was once writing a class that would need to encapsulate roughly 30~40 operations on an object. To my pleasant surprise, I realized the combinations of less than 5 or so member functions could completely process the rest of the members, and in a very clean way. So in essence, the class repeated very little if any code, since most calls were either directly or recursively solved by the small handful of workers.
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

  9. #9
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Hello World!!!

    AHAHAHAHAHAHAHA

  10. #10
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    have you noticed how zeros keep gettign added to the amount of code?? lol

    but yeah, just decide for yourself what's brilliant (don't worry light, we won't criticize hack code )

    Here's some sweet stuff i came up with for web pages:
    someone wanted to do backgrounds that were lighter in a table cell than the normal color, i came up with using the IE alpha filter...then the text in the cell got too light, so i came up with this (for some reason the text doesn't seem to be wrapping like it used to on the new cell)
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    	<HEAD>
    		<TITLE>Alpha Filter Example</TITLE>
    		<STYLE type="text/css">
    		.aFilter
    					{
    						FILTER: progid:DXImageTransform.Microsoft.Alpha(opacity=50)
    					}
    		</STYLE>
    	</HEAD>
    	<BODY bgcolor="blue">
    		<TABLE>
    			<TR>
    				<TD bgcolor="red" class=aFilter height="100px" width="200px">
    				</TD>
    				<TD style='position:relative;top:"0px";left:"-200px";'>
    					<FONT color="white">
    						This is clear text over an alpha background
    					</FONT>
    				</TD>
    			</TR>
    		</TABLE>
    	</BODY>
    </HTML>
    This next one is simple, but it's the best way to do it. (referring to lights idea of brilliant)
    some one wanted to make a web based way of making web pages for quick testing, i said here ya go. they wantedthe start of an editor
    Code:
    <html>
         <head>
              <script language="javascript">
                   var newWindow;
                   function parseIt()
                   {
    				    var parsedContent=document.forms[0].theText.value;
                        newWindow=window.open("","","Height=300,Width=300");
                        newWindow.document.write(parsedContent);
                   }
              </script>
         </head>
         <body>
              <form>
                   <textarea id="theText">
                        Type HTML Here
                   </textarea>
                   <button id="theButton" onclick="parseIt()">
                        Parse
                   </button>
              </form>
         </body>
    </html>
    and the final one was a way to get to the bottom of a page, someone suggested scrolling down 10,000px..i found a better way
    Code:
    <html>
    	<head>
    		<script language="javascript">
    			var bottomOut=document.body.clientHeight;
    		</script>
    	</head>
    	<body onload="javascript:scrollTo(0,bottomOut);">
    	</body>
    </html>
    you can go ahead and try these examples, theyr'e pretty neat, the last example needs to be put in an existing page though, otherwise you don't get any effect without anything to scroll through.
    PHP and XML
    Let's talk about SAX

  11. #11
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    mostin interesting code was a simple network messaging system in C, a simpler version in assembler and i wrote unix ls aswell (harder than you think - uses loops upto septh 6)
    Monday - what a way to spend a seventh of your life

  12. #12
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by lightatdawn
    Good god man! I just ran C-Metrics on my system and discovered I have only 116,077 lines of my own [strictly C++] code on this entire computer.
    That was a nice program. Make me think a bit though...
    I've been programming C++ since 1999 and I had 216,475 lines of code in my C++ folder.

    162 lines of code / day ??

    Hopefully some of those lines were automatically generated by Borland or something.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  13. #13
    Banned Cgawd's Avatar
    Join Date
    Oct 2002
    Posts
    405
    brilliant code
    Code:
    int main()
    {
    
    return 0;
    }

  14. #14
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    Originally posted by Cgawd
    brilliant code
    Code:
    int main()
    {
    
    return 0;
    }
    no, THIS, is truly brilliant:
    Code:
    void main()
    {
    }
    PHP and XML
    Let's talk about SAX

  15. #15
    Banned Cgawd's Avatar
    Join Date
    Oct 2002
    Posts
    405
    until you need to return an int to the OS and you FORGET HOW. "all i know is void...omg what am i going to do".

    hehe

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21