Author Topic: Coding Horror: Why Can't Programmers Program?  (Read 18829 times)

0 Members and 1 Guest are viewing this topic.

Re: Coding Horror: Why Can't Programmers Program?
Some dialect of basic in 3.25 mins: (and thats including a rewrite half way through  :drevil:)
Code: [Select]
for A=1 to 100
  B$=""
  if A mod 3=0 then B$="Fizz"
  if A mod 5=0 then B$=B$+"Buzz"
  if B$="" then B$=str$(A)
  ? B$
next a

That article was a little shocking.  I wouldn't think myself a good programmer but to find that those people have trouble with something that would have been printed in a 1980's "Getting started with basic" book... and usually something that would be printed near the beginning!
Find me as Hojo Norem elsewhere...

butter_pat_head... a name picked in sheer desperation more than 10 years ago from some super obscure Red Dwarf reference.

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Coding Horror: Why Can't Programmers Program?
one must also consider that lua is a very high level language. its interpreted and not really compiled. it can be compiled to bytecode but that is not necessary to make it work. for readability lua is hard to beat, its also the simplest language ive ever worked with. so i have no idea what the computer is being asked of when i type a statement. the most programming classes ive had were 3 semesters in high school. they mainly taught c/c++ and vb. for some reason i spent most of my time screwing around with vb (and really didnt accomplish anything better than pong).
« Last Edit: February 28, 2010, 02:51:20 pm by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Mongoose

  • Rikki-Tikki-Tavi
  • Global Moderator
  • 212
  • This brain for rent.
    • Minecraft
    • Steam
    • Something
Re: Coding Horror: Why Can't Programmers Program?
Just about all of the coding classes I took used C/C++ from the Unix command line, save one taught in Scheme (a form of LISP) that I pretty much hated.  Even today, I have little to no idea how Visual C++ actually functions. :p

 

Offline Topgun

  • 210
Re: Coding Horror: Why Can't Programmers Program?
I can explain it for you if you don't mind my bad English :P

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Coding Horror: Why Can't Programmers Program?
I can explain it for you if you don't mind my bad English :P

its probibly the same under detailed over plagiarized explanation that wikipedia has :D
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Topgun

  • 210
Re: Coding Horror: Why Can't Programmers Program?
basically its like this,

there are variables that the os can send to the program like where the mouse cursor is, what keys are being pressed ect. the program catches these variables and does what it wants with them (like rendering the cursor or whatever).
its easier to explain this with some psudo-code:

while (WINDOW_HAS_FOCUS AND I_want_to_draw_something)
{
int draw_cursor (CURSOR_LOCATION, BUTTON_PRESSED)

{

-------do some stuff-----


}
I_want_to_draw_something = false;
}

so every cycle the os gives the program, the condition WINDOW_HAS_FOCUS is checked. of its true, and the program wants to draw the cursor, then the function is called and draws the cursor.

thats the basic idea of windows programming, what visual studio does is it turns all that into objects
so you would have something like this:

class Cursor

int X_LOCATION
int Y_LOCATION
bool is_clicked

method_DRAW()

yeah I know that's not anywhere near valid C++ but whatever, its psudocode. anyway, when you write something in visual studio to do something on an event all it does is create a method that gets called when one of those variables the os gives you is true.

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Coding Horror: Why Can't Programmers Program?
yeah I know that's not anywhere near valid C++ but whatever, its psudocode. anyway, when you write something in visual studio to do something on an event all it does is create a method that gets called when one of those variables the os gives you is true.

.... Seriously? You think that's "Visual C"?

You just described just one of the many, many functions a full IDE like Visual Studio provides. "Visual C" is just a shorthand for "Visual Studio, preconfigured for development using C/C++". Please learn the terms before trying to describe them, kthx.

While you're at it, please research topics like "Object-oriented programming", Microsoft Foundation Classes, and Windows Presentation Foundation.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 
Re: Coding Horror: Why Can't Programmers Program?
yeah I know that's not anywhere near valid C++ but whatever, its psudocode. anyway, when you write something in visual studio to do something on an event all it does is create a method that gets called when one of those variables the os gives you is true.

.... Seriously? You think that's "Visual C"?

You just described just one of the many, many functions a full IDE like Visual Studio provides. "Visual C" is just a shorthand for "Visual Studio, preconfigured for development using C/C++". Please learn the terms before trying to describe them, kthx.

While you're at it, please research topics like "Object-oriented programming", Microsoft Foundation Classes, and Windows Presentation Foundation.

Well it looked a bit like MFC.... which in itself is a coding horror LOL
That's cool and ....disturbing at the same time o_o  - Vasudan Admiral

"Don't play games with me. You just killed someone I like, that is not a safe place to stand. I'm the Doctor. And you're in the biggest library in the universe. Look me up."

"Quick everyone out of the universe now!"

 

Offline blackhole

  • Still not over the rainbow
  • 29
  • Destiny can suck it
    • Black Sphere Studios
Re: Coding Horror: Why Can't Programmers Program?
Code: [Select]
#include <iostream>

using namespace std;

int main()
{
  for(int i = 1; i <= 100; ++i)
  {
    if(!(i%3) && !(i%5))
      cout<<"FizzBuzz"<<endl;
    else if(!(i%3))
      cout<<"Fizz"<<endl;
    else if(!(i%5))
      cout<<"Buzz"<<endl;
    else
      cout<<i<<endl;
  }
  return 0;
}

About 90 seconds, since everyone else here seems to want to prove they can do it.

EDIT: Whoops, misread the prompt. Make that 170 seconds for time spent fixing it :(
« Last Edit: February 28, 2010, 08:18:23 pm by blackhole »

 
Re: Coding Horror: Why Can't Programmers Program?
Ok how about this:

Code: [Select]
using System;

namespace FizzBuzz
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {

            for (int loop = 1; loop <= 100; ++loop)
            {
                bool divBy3 = (loop % 3) != 0;
                bool divBy5 = (loop % 5) != 0;

                if (divBy3 && divBy5)
                {
                    Console.WriteLine ("FizzBuzz") ;
                }
                else if (divBy3)
                {
                    Console.WriteLine("Fizz");
                }
                else if (divBy5)
                {
                    Console.WriteLine("Buzz");
                }
                else
                {
                    Console.WriteLine(loop.ToString());
                }
            }
        }
    }
}
That's cool and ....disturbing at the same time o_o  - Vasudan Admiral

"Don't play games with me. You just killed someone I like, that is not a safe place to stand. I'm the Doctor. And you're in the biggest library in the universe. Look me up."

"Quick everyone out of the universe now!"

 

Offline Aardwolf

  • 211
  • Posts: 16,384
    • Minecraft
Re: Coding Horror: Why Can't Programmers Program?
Ok how about this:
*snip*

Lol, cookie-cutter code.

* Aardwolf shortens it, for no benefit.

Code: [Select]
using System;

namespace FizzBuzz
{
    static class Program
    {
        static void Main()
        {
            for (int loop = 1; loop <= 100; ++loop)
            {
                bool divBy3 = (loop % 3) != 0;
                bool divBy5 = (loop % 5) != 0;

                if (divBy3 && divBy5)
                    Console.WriteLine ("FizzBuzz") ;
                else if (divBy3)
                    Console.WriteLine("Fizz");
                else if (divBy5)
                    Console.WriteLine("Buzz");
                else
                    Console.WriteLine(loop.ToString());
            }
        }
    }
}

  
Re: Coding Horror: Why Can't Programmers Program?
LOL well isn't that what this is heading towards? LOL
Actually I check % only twice the entire loop cycle.  I keep track via bool flags.

Also I would have liked to gotten rid of at least one of the if statements, but I don't think that's possible.  If it was doing 3 or 5 then it would be a lot simplier.
« Last Edit: February 28, 2010, 10:22:16 pm by Scooby_Doo »
That's cool and ....disturbing at the same time o_o  - Vasudan Admiral

"Don't play games with me. You just killed someone I like, that is not a safe place to stand. I'm the Doctor. And you're in the biggest library in the universe. Look me up."

"Quick everyone out of the universe now!"

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Coding Horror: Why Can't Programmers Program?
It's possible to do it in 3 if statements and no else but the result is more complex code.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 
Re: Coding Horror: Why Can't Programmers Program?
Code: [Select]
void fizzbuzz( )
{
  bool a = false, b = false;
  do
  {
     a = ( i % 3 == 0 );
     b = ( i % 5 == 0 );
     if ( a )
       printf( "Fizz" );
     if ( b )
       printf( "Buzz");
     if ( !( a||b ) )
        printf("%d", i );
     printf("\n");
  } while( i != 100 );
}

I missed a step when I thought nuke was a little suboptimal. The above is the best I've got at the moment.
STRONGTEA. Why can't the x86 be sane?

 
Re: Coding Horror: Why Can't Programmers Program?
I think that's what I was trying to achieve.
That's cool and ....disturbing at the same time o_o  - Vasudan Admiral

"Don't play games with me. You just killed someone I like, that is not a safe place to stand. I'm the Doctor. And you're in the biggest library in the universe. Look me up."

"Quick everyone out of the universe now!"

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Coding Horror: Why Can't Programmers Program?
Code: [Select]
for i=1, 100 do
 if i%3 == 0 and i%5 == 0 then
  print("FizzBuzz")
 elseif i%3 == 0 then
  print("Fizz")
 elseif i%5 == 0 then
  print("Buzz")
 else
  print(tostring(i))
 end
end

aparently lua supports an operator for modulo
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
Re: Coding Horror: Why Can't Programmers Program?
all you people doing fancy stuff would get penalized for prematurely optimizing your code.
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Coding Horror: Why Can't Programmers Program?
Yep. The optimised code is much less readable and relies on people realising that for values divisible by 15 both Fizz and Buzz will be outputted.

In return for that it gains a fairly questionable speed increase (and possibly depending on the method maybe the ability to be modified later to add other options).
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Spicious

  • Master Chief John-158
  • 210
Re: Coding Horror: Why Can't Programmers Program?
I think everyone who's trying to code it up in brilliant ways has completely missed the point of the article.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Coding Horror: Why Can't Programmers Program?
Not really. They just have a better understanding of what's going to happen than the writers of the article.

If you're asked to code something at a job interview you're going to write the best code you possibly can to solve the problem even if you're told that the idea is to sort out the programmers from non-programmers. Nobody is going to believe that the quality of your solution is only going to be looked at as a pass-fail.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]