Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: question about programming in genral  (Read 6667 times)

0 Members and 1 Guest are viewing this topic.

mat123

    Topic Starter


    Hopeful

    Thanked: 16
    • Yes
    • Yes
    • Yes
  • Experience: Familiar
  • OS: Windows XP
question about programming in genral
« on: February 12, 2011, 04:37:39 AM »
my question is does anyone else get agitated when there is a variable and the next line uses the variable? ex
Code: [Select]
int var=0;
if (var==0)
    cout <<"var is equal to 0";



Salmon Trout

  • Guest
Re: question about programming in genral
« Reply #1 on: February 12, 2011, 05:46:08 AM »
does anyone else get agitated when there is a variable and the next line uses the variable?

Why should anyone get agitated? Do you mean the use of "magic numbers"? Not quite sure what you mean. Demo code that is written to demonstrate some point or other (e.g. conditional execution) is not to be taken as providing a style guide.

umbra



    Beginner
  • Thanked: 2
    • Experience: Familiar
    • OS: Windows 7
    Re: question about programming in genral
    « Reply #2 on: February 12, 2011, 07:42:39 AM »
    Hi,

     In my opinion that code is only for learning how to write some school programs, never in production something like that should be used.

     I supposed its purpose is only a didactic one, and yes i saw many times code like that but i never become agitated because was never used in production.

    All the best.
    Trying to don't waste my time.  :)

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: question about programming in genral
    « Reply #3 on: February 12, 2011, 10:06:16 AM »
    It doesn't make a bit of difference. the compiled code is still the same, unless the variable is then used in a for, like this:

    Code: [Select]
    int i=0;
    for(int i=5;i<5;i++)
    {
    //code
    }
    Except in that case the inner definition of i simply shadows the "outer" definition of i (and in many languages you simply get a duplicate definition error so you can't do it anyway.


    The example is silly because the if is redundant, as well.

    Neither one is easier to read, and there is no reason to use one over another, even in the apparently magical whimsical fairlyland of "production" where apparently the requirements change to require code to adhere to redundant ruleset's based on a single persons subjective view.
    I was trying to dereference Null Pointers before it was cool.

    mat123

      Topic Starter


      Hopeful

      Thanked: 16
      • Yes
      • Yes
      • Yes
    • Experience: Familiar
    • OS: Windows XP
    Re: question about programming in genral
    « Reply #4 on: February 12, 2011, 03:48:17 PM »
    the point is that the if is redundant i get annoyed when people do that when the result of the conditional statement is determined at compile time rather then run time.



    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: question about programming in genral
    « Reply #5 on: February 12, 2011, 05:23:41 PM »
    Quote
    the point is that the if is redundant i get annoyed when people do that when the result of the conditional statement is determined at compile time rather then run time.
    If you were a Jr programmer, and I was a Sr. I would say that you leave it the way I want it and I will tell you way next year. If you are still with us. Team players learn to work together, even when the reason for something is not readily apparent.

    But.. that  is not the case. Do you want to know why we put that in production code? Go ahead, ask me.
    Quote
    int var=0;
    if (var==0)
        cout <<"var is equal to 0";



    Salmon Trout

    • Guest
    Re: question about programming in genral
    « Reply #6 on: February 12, 2011, 05:30:58 PM »
    the point is that the if is redundant i get annoyed when people do that when the result of the conditional statement is determined at compile time rather then run time.

    But you are always going to find amazingly bad code. I don't think there is any point whatsoever in getting emotionally involved with source code. Maybe you should go out more?

    How to write bad code:

    http://www.exmsft.com/~hanss/badcode.htm


    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: question about programming in genral
    « Reply #7 on: February 12, 2011, 07:13:48 PM »
    The above link took the words out of my mouth.
    Quote
    Job security
    if you're the only one that can work on a piece of code that they need, they can't fire you. The flip side of this is that they can't let you go work on anything else. Being able to really screw up a piece of code and then ducking out to go screw up another project too is a truly special talent that only a few have demonstrated.
      8)

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    I was trying to dereference Null Pointers before it was cool.

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: question about programming in genral
    « Reply #9 on: February 12, 2011, 09:19:38 PM »
    http://thedailywtf.com/Articles/14-Layers-Deep.aspx
    I Love it!
    Does the OP still want to know why professional developers write such bloated code? It is one way to keep the completion from knowing how easy it could be.

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    I was trying to dereference Null Pointers before it was cool.

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: question about programming in genral
    « Reply #11 on: February 12, 2011, 11:36:13 PM »
    He forgot about leap year!  :o
    Where do you find this stuff, BC?  ;D

    BTW, you can buy a digital watch in the Dollar Tree, a variety store, for just $1. If  the date is wrong non March 1st, you just click a couple of buttons an  it will be OK for the next four years. Why can't they put buttons on every computer so that the user can just press buttons if a program is wrong?

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: question about programming in genral
    « Reply #12 on: February 13, 2011, 09:16:56 AM »
    Where do you find this stuff, BC?  ;D
    I'm subscribed to TDWTF via RSS; I also lurk and occasionally post on the forums when the forum software there isn't in "haiku mode".

    Quote
    Why can't they put buttons on every computer so that the user can just press buttons if a program is wrong?

    That applies to a lot more then software. "Why can't they put buttons in a fighter jet so the pilot can just press buttons and win dogfights?"
    I was trying to dereference Null Pointers before it was cool.

    Salmon Trout

    • Guest
    Re: question about programming in genral
    « Reply #13 on: February 13, 2011, 09:21:19 AM »
    Why can't they put buttons on TV sets to make the programmes more interesting?

    One day you'll get quoting right, BC_P...




    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: question about programming in genral
    « Reply #14 on: February 13, 2011, 09:24:34 AM »
    One day you'll get quoting right, BC_P...

    fixed  :P
    I was trying to dereference Null Pointers before it was cool.