News:

Holy shit, it's 2018 2019 2020 2021 2022 2023 2024, and the US isn't a fascist country! What a time to be alive. Well, shit.

Main Menu

Fahrenheit <=> Celsius Converter

Started by Joe, April 09, 2006, 01:56:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Joe

I got annoyed at Blaze for correcting me, saying Winnipeg was 9 degrees, when I said it was 48 (same thing). So, I wrote this~
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


deadly7

(9^2)/5 = 16.2
16.2+32 = 48.2
You both lose.
[17:42:21.609] <Ergot> Kutsuju you're girlfrieds pussy must be a 403 error for you
[17:42:25.585] <Ergot> FORBIDDEN

on IRC playing T&T++
<iago> He is unarmed
<Hitmen> he has no arms?!

on AIM with a drunk mythix:
(00:50:05) Mythix: Deadly
(00:50:11) Mythix: I'm going to fuck that red dot out of your head.
(00:50:15) Mythix: with my nine

Sidoh


iago

Quote from: MyndFyrex86] link=topic=5504.msg64352#msg64352 date=1144623310]
Quote from: Quik on April 09, 2006, 06:36:20 PM
The point is that he's practicing programming and (supposedly) learning new things.

I might say that he's not.  He's still doing typical Joe things.  For instance:
He's still learning.  He'll especially learn from criticisms that you provide, but it helps if you don't phrase it in such a negative way.  Is it really necessary to have a "you're an idiot" tone when a "this would be better" tone would suffice?

Quote from: MyndFyrex86] link=topic=5504.msg64352#msg64352 date=1144623310]

if ((args.length == 0) || (args.length == 1))

How about:

if (args.length < 2)

so that we only need one runtime check if args.length == 1?
I like Joes way better.  The code will end up the same after being compiled, but Joe's way is more clear to people reading it. 

MyndFyre

Quote from: iago on April 10, 2006, 12:07:12 PM
Quote from: MyndFyrex86] link=topic=5504.msg64352#msg64352 date=1144623310]

if ((args.length == 0) || (args.length == 1))

How about:

if (args.length < 2)

so that we only need one runtime check if args.length == 1?
I like Joes way better.  The code will end up the same after being compiled, but Joe's way is more clear to people reading it. 
Uhh, wha-?

That might be the case in Java, but *only* for the length property.  The thing about some languages such as Java, C, C#, etc. is that by calling methods you could inadvertantly change the class.

For example, if (instead of saying .length), you had to use a function like .getLength(), Java would have no way of knowing that the array object didn't change state and that it could optimize it out.  C fortunately offers that option to intelligent programmers:

class CArray {
  public:
    int getLength() const;
}

with the const modifier on class methods.

The problem is that what the assembler will produce is something like this:

mov    eax, [edx+08h]   ; current
cmp    eax, 0
jz       conditional_okay
cmp    eax, 1
jnz      conditional_false
conditional_okay:
  ; do stuff inside the conditional scope

conditional_false:
  ; ...

Whereas with my way, there's only one conditional evaluation:

mov    eax, [edx+08h]
cmp    eax, 2
jge     conditional_false
; do stuff inside the conditional scope
conditional_false:
; else --

Now, let's say that we're calling a method (non-virtual) from a class that's not marked const:

mov    edx, [ebx+08h]
call     edx
cmp    eax, 0
jz       conditional_okay
mov    edx, [ebx+08h] ; depending on whether edx was overwritten, this instruction may be unnecessary.  The linker knows.
call     edx
cmp    eax, 1
jnz      conditional_false
conditional_okay:
  ; do stuff inside the conditional scope

conditional_false:
  ; ...


Hopefully you see the problem.

Plus, what if Joe made a "debuffer" in Java?  Then, using this line of coding would be something like:

if (pck.getInt32() == 0 || pck.getInt32() == 1)

which would DEFINITELY lead to runtime errors as he read too quickly through a packet where this value did not initially equal zero.

The other nice thing about my method, besides what I've already given you, is that it guards you from some exceptional cases.  For example, the .indexOf function returns -1 when it cannot find an instance of the specified string within another string.  This is an exceptional case -- it shouldn't require an Exception object, but it should be able to be handled.
Quote from: Joe on January 23, 2011, 11:47:54 PM
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Quote from: Rule on May 26, 2009, 02:02:12 PMOur species really annoys me.

iago

Uhh, what?  Aren't we talking about commandline parameters?

He wants to know if there are 0 or 1 commandline parameters.  Anybody who views his source will instantly see that he is looking for 0 or 1 commandline paremeters.  If he uses <2, then I stop and think, "Less than 2, that's 1 and 0 and negatives.  But negatives can't be here, so just 1 and 0."  Whereas if he uses 0||1, I think "Ah, he needs 0 or 1 parameters".  That's it! 

In other cases, it really depends on the situation.  But in this case, I prefer to spell out the exact number of parameters I want, not use a < or > comparison. 

The main point is, you're complaining about his coding style there.  He does it one way, you do it another.  That doesn't make you right and him wrong, or vice versa. 


Blaze

I knew that his formula wasn't the one I used, but was too lazy to see if it worked out.  :)
And like a fool I believed myself, and thought I was somebody else...