Hi All,

This reminds me of the first C program I ever wrote as a freshman in  
college working at ARL in 2000.  I had to download a waveform from a  
file to an arbitrary waveform generator (arb) for work.  http:// 
tinyurl.com/2ga8g3

With my trusty Schaum's Outline of Programming with C and a rummaged  
up Borland Turbo C compiler for DOS, I set about writing it.

After a couple of days struggling with pointers, C arrays, and the  
serial port, I managed to get the arb clicking in response to my  
code!  There was a problem though, because once all the data got sent  
the screen displayed ERR.  By getting it to respond at all, I was  
reasonably sure it should be working correctly (haha yeah right).

Well, I talked to my boss and he decided I should ask an expert.  The  
exchange went like this:

    Expert: How are you opening the file?
    Me: With fopen()!
    Expert: Are you opening it in text or binary mode?
    Me: ???

My code was something like:

    FILE *f = fopen("waveform.bin", "r");

Of course, the correct code is:

    FILE *f = fopen("waveform.bin", "rb");

The b is for binary.

Making that small change and adding some calls to sleep() so my  
program wouldn't fill up the arb's transfer buffer too quickly fixed  
everything.

Opening the file in text mode changed my data!!!  It took some  
serious newb debugging and help from an expert to figure out the  
crazy default mode for fopen.

Even though I was just a beginning programmer, I would have known to  
open the file in binary mode /IF I had been given the option/.  C's  
default-to-text-mode fopen got me bad.

Doug


On Mar 10, 2008, at 4:09 AM, Eduardo Cavazos wrote:

>
> Slava wrote:
>
>> But with replacement characters, having a UTF8 default with no
>> indication that it is UTF8 would lead to confusion among newbies
>> attempting to read binary files.
>
> Let's assume the newbie is living in mandatory encoding parameter  
> land.
>
> The newbie, being a typical newbie, learned about <file-writer> by  
> seeing it
> used in some code. He saw "..." utf8 <file-writer>.
>
>       Statistically speaking, based on encoding distributions, he is  
> most likely to
>       see that incantation, with the 'utf8'.
>
> Now, this guy is a newbie. We're talking, Factor is his first  
> programming
> language. So, what does he do? He pastes that code into his program  
> when
> trying to read his jpeg... and confusion ensues.
>
> I think it's an awful idea to optimize for the newbie at the  
> expense of the
> hacker and elegance of the language.
>
> It's even more awful that a design desicion made on behalf of the  
> imagined
> newbie doesn't even help that much.
>
> What if the "newbie" doesn't want to read binary, but wants to read  
> text? He's
> forced to choose from one of four symbols. This guy's never programmed
> before. Are you ready to give him a tutorial on unicode? If so, be  
> prepared
> for more confusion. Why?
>
>       I know veteran programmers who are confused by unicode
>
> When newbies (like students in cs classes) have programming  
> assignments, isn't
> it common for them to have to read from "text" files?
>
> And never mind that newbies are more likely to read from text than  
> from
> binary. Just look at the core Factor implementation. Or the  
> contributed
> libraries. Even we use utf8 the most.
>
> Going with a default of "utf8" and an optional setting of  
> "binary" (for the
> arguably exceptional cases) is more beneficial to newbies and, I  
> would argue,
> is a "humane interface" in the spirit of Jef Raskin.
>
> Ed
>
> ---------------------------------------------------------------------- 
> ---
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Factor-talk mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to