Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: size of

Reply
Thread Tools

Re: size of

 
 
Malcolm McLean
Guest
Posts: n/a
 
      08-17-2013
On Saturday, August 17, 2013 9:35:18 PM UTC+1, Keith Thompson wrote:
> Malcolm McLean <(E-Mail Removed)> writes:
>
>
> > No, that's how a geek writes an allocation call.

>
> Yes, it is.
>
> Unless you meant "geek" to be a derogatory term, in which case you're
> spewing nonsense.
>

It's a way of thinking. Here it's semi- derogatory, because it's caused
them to do something which I disapprove of.
>
> So we should write fragile code so that readers who are unfamiliar with
> the language can read it a little more easily? But you're assuming they
> know what "malloc" means, and that "=" means assignment and "*" means
> multiplication.
>

There's been an explosion of languages. I'm frequently finding myself having
to read code in languages I don't understand. It's not normally a very
high bar. Neglecting lisp family of languages for the moment, all languages
are going to have loops and conditional branches and function calls,
variables, blocks with scope, strings, some sort of string output statement,
and probably objects/structures, maybe with inheritance. You can read the
code, work out what it;s doing, correct it or modify it, or translate
the algorithm into some other language.

But you get the occasional really odd construct. Then it's a real barrier,
particularly if it's not easily referencable. If you read "ugglewuggle"
in superlanguage X, then you type the word into Google and find out what
it means. But if the odd construct is x <- |*y| then that's a problem.
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      08-18-2013
Malcolm McLean <(E-Mail Removed)> writes:
> On Saturday, August 17, 2013 9:35:18 PM UTC+1, Keith Thompson wrote:
>> Malcolm McLean <(E-Mail Removed)> writes:
>> > No, that's how a geek writes an allocation call.

>>
>> Yes, it is.
>>
>> Unless you meant "geek" to be a derogatory term, in which case you're
>> spewing nonsense.
>>

> It's a way of thinking. Here it's semi- derogatory, because it's caused
> them to do something which I disapprove of.


As I thought, you're spouting nonsense.

C is not the easiest language in the world. If you don't understand
what a fairly common construct means (and this one is fairly common),
you probably shouldn't be working on C code.

Again, *you* know what it means; why do you have such a low opinion of
others?

[...]

> But you get the occasional really odd construct. Then it's a real barrier,
> particularly if it's not easily referencable. If you read "ugglewuggle"
> in superlanguage X, then you type the word into Google and find out what
> it means. But if the odd construct is x <- |*y| then that's a problem.


There are any number of resources someone could use to find out what

int *ptr = malloc(42 * sizeof *ptr);

In fact, this example:

int *ptr;
ptr = malloc(10 * sizeof (*ptr));

appears in the Wikipedia article on malloc.

And as I mentioned upthread, *you* seem to have figured it out. I'm not
going to limit my use of C features to those that are easy to Google.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
 
Tim Rentsch
Guest
Posts: n/a
 
      08-21-2013
Malcolm McLean <(E-Mail Removed)> writes:

> On Saturday, August 17, 2013 3:36:27 AM UTC+1, Eric Sosman wrote:
>>
>>
>> int *ptr = malloc(42 * sizeof *ptr);
>>
>>
>> - The fourth is an example of the allocation pattern favored
>> by thoughtful C programmers, but it *relies* on `*ptr' not
>> being evaluated by `sizeof'. (If `*ptr' were evaluated at
>> that moment, before it had been initialized, the effect of
>> trying to dereference the garbage pointer would be
>> undefined).

>
> No, that's how a geek writes an allocation call.
>
> What he's thinking is that if ptr is changed to a long *, the code
> won't break. And he's right. It is a genuine advantage. But the
> price is a construct which is meaningless to human reader, unless
> he's very familiar with C. [snip elaboration]


Only a fool worries about whether his program will be
comprehensible to an incompetent programmer.
 
Reply With Quote
 
Malcolm McLean
Guest
Posts: n/a
 
      08-21-2013
On Wednesday, August 21, 2013 8:29:39 AM UTC+1, Tim Rentsch wrote:
> Malcolm McLean <(E-Mail Removed)> writes:
>
>
> Only a fool worries about whether his program will be
> comprehensible to an incompetent programmer.
>

Everything must be as clear as day. Often the algorithm is difficult
enough, without adding the extra burden of syntax designed to meet the
needs of machines rather than human readers.

 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      08-21-2013
In article <(E-Mail Removed)>,
Tim Rentsch <(E-Mail Removed)> wrote:
....
>Only a fool worries about whether his program will be
>comprehensible to an incompetent programmer.


heh heh.

I think what you meant to write is:

>Only someone who doesn't care about staying employed can afford the luxury
>of not worrying about whether his program will be
>comprehensible to other (generally incompetent[*]) programmers.


>[*] See: Sturgeon's Law...


Yes. BTDT.

--
Here's a simple test for Fox viewers:

1) Sit back, close your eyes, and think (Yes, I know that's hard for you).
2) Think about and imagine all of your ridiculous fantasies about Barack Obama.
3) Now, imagine that he is white. Cogitate on how absurd your fantasies
seem now.

See? That wasn't hard, was it?

 
Reply With Quote
 
Joe Pfeiffer
Guest
Posts: n/a
 
      08-21-2013
Malcolm McLean <(E-Mail Removed)> writes:

> On Saturday, August 17, 2013 3:36:27 AM UTC+1, Eric Sosman wrote:
>>
>>
>> int *ptr = malloc(42 * sizeof *ptr);
>>
>>
>> - The fourth is an example of the allocation pattern favored
>> by thoughtful C programmers, but it *relies* on `*ptr' not
>> being evaluated by `sizeof'. (If `*ptr' were evaluated at
>> that moment, before it had been initialized, the effect of
>> trying to dereference the garbage pointer would be undefined).
>>

> No, that's how a geek writes an allocation call.
>
> What he's thinking is that if ptr is changed to a long *, the code won't
> break. And he's right. It is a genuine advantage. But the price is a construct
> which is meaningless to human reader, unless he's very familiar with C.
> As you say it looks like *ptr should yield something, but ptr is currently
> wild. Then we've got another use of the * operator. Finally, it's not
> obvious that sizeof is not an identifier, it's not clear what its scope is.
> Could sizeof * be sizeof a wildcard, which is somehow applied to ptr?
>
> ptr = malloc(42 * sizeof(int));
>
> is far more readable. Everyone can see that we're allocating a space for 42
> ints.


It's a construct that takes 30 seconds of education the first time you
see it, after which you file it away as one more way to make your code
better.

Somebody who reads '*' in a C program as a wildcard? Seriously?
 
Reply With Quote
 
Tim Rentsch
Guest
Posts: n/a
 
      08-23-2013
(E-Mail Removed) (Kenny McCormack) writes:

> In article <(E-Mail Removed)>,
> Tim Rentsch <(E-Mail Removed)> wrote:
> ...
>> Only a fool worries about whether his program will be
>> comprehensible to an incompetent programmer.

>
> heh heh.
>
> I think what you meant to write is:
>
>> Only someone who doesn't care about staying employed can afford the
>> luxury of not worrying about whether his program will be
>> comprehensible to other (generally incompetent[*]) programmers.
>>
>>[*] See: Sturgeon's Law...


No, I meant what I wrote. The two statements are related
but they are not incompatible.
 
Reply With Quote
 
Tim Rentsch
Guest
Posts: n/a
 
      08-23-2013
Malcolm McLean <(E-Mail Removed)> writes:

> On Wednesday, August 21, 2013 8:29:39 AM UTC+1, Tim Rentsch wrote:
>>
>> Only a fool worries about whether his program will be
>> comprehensible to an incompetent programmer.

>
> Everything must be as clear as day. Often the algorithm is
> difficult enough, without adding the extra burden of syntax
> designed to meet the needs of machines rather than human readers.


Apparently you either missed the point of my comment or
didn't bother looking for it.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      08-23-2013
Tim Rentsch <(E-Mail Removed)> writes:
> Malcolm McLean <(E-Mail Removed)> writes:
>> On Wednesday, August 21, 2013 8:29:39 AM UTC+1, Tim Rentsch wrote:
>>> Only a fool worries about whether his program will be
>>> comprehensible to an incompetent programmer.

>>
>> Everything must be as clear as day. Often the algorithm is
>> difficult enough, without adding the extra burden of syntax
>> designed to meet the needs of machines rather than human readers.

>
> Apparently you either missed the point of my comment or
> didn't bother looking for it.


Or he got the point and disagrees with it. (I think you're right and
he's wrong, but what do I know?)

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Tim Rentsch
Guest
Posts: n/a
 
      08-25-2013
Keith Thompson <(E-Mail Removed)> writes:

> Tim Rentsch <(E-Mail Removed)> writes:
>> Malcolm McLean <(E-Mail Removed)> writes:
>>> On Wednesday, August 21, 2013 8:29:39 AM UTC+1, Tim Rentsch wrote:
>>>> Only a fool worries about whether his program will be
>>>> comprehensible to an incompetent programmer.
>>>
>>> Everything must be as clear as day. Often the algorithm is
>>> difficult enough, without adding the extra burden of syntax
>>> designed to meet the needs of machines rather than human readers.

>>
>> Apparently you either missed the point of my comment or
>> didn't bother looking for it.

>
> Or he got the point and disagrees with it.


Possible. If so that isn't being communicated very effectively,
which under the circumstances would be rather ironic.

> (I think you're right and he's wrong, but what do I know?)


I was trying to think of something clever to say here, but
all I could think of was "ditto."
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Preferred Size, Minimum Size, Size Jason Cavett Java 5 05-25-2008 08:32 AM
mega pixels, file size, image size, and print size - Adobe Evangelists Frank ess Digital Photography 0 11-14-2006 05:08 PM
How to set the DataGrid Row Size to a fixed size. =?Utf-8?B?QmlkYXJrb3Rh?= ASP .Net 0 05-19-2005 08:14 PM
Using <asp:label font-size=16px...> ist not showing size in FireFox Browser Andreas Klemt ASP .Net 6 11-28-2004 09:21 PM
Dynamic Size for Text Box - Expanding more than the relative size Madhanmohan S ASP .Net 5 09-03-2004 06:28 AM



Advertisments