Two Plus Two Publishing LLC
Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > >

Notices

Programming Discussions about computer programming

Reply
 
Thread Tools Display Modes
Old Yesterday, 04:35 PM   #36351
goofyballer
 
goofyballer's Avatar
 
Join Date: Jun 2005
Posts: 64,914
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Like, "benchmark it and figure it out for yourself" is also a good answer to that question because of it being implementation-dependent - but if you had to pick an answer to "which is more efficient" of either "they're the same" or "they're not the same" (the latter implying you can say one is better than the other, which, no, you can't without knowing the implementation) - the first is, semantically, more accurate, at least with regards to the part the question was asking about (efficiency, not the return value).
goofyballer is offline   Reply With Quote
Old Yesterday, 04:56 PM   #36352
jmakin
 
jmakin's Avatar
 
Join Date: Jan 2008
Location: Streaming
Posts: 29,160
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Ok maybe i am just being nitpicky. I always tend to call with (n,1).
jmakin is online now   Reply With Quote
Old Yesterday, 05:03 PM   #36353
jmakin
 
jmakin's Avatar
 
Join Date: Jan 2008
Location: Streaming
Posts: 29,160
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Quote:
Originally Posted by microbet View Post
I don't fget any of that, so feel free to explain which way is better and why.


fread will read from a file into a buffer like this:

fread(buffer, n, nmemb, file pointer)

n is the number of bytes you are requesting nmemb times, so if you do fread(buffer, 1, 8192, fp) you are requesting 1 byte read 8192 times, vs 8192 bytes 1 time. Then it will return whatever the successful number of nmemb reads was.

but fread will (presumably) read byte by byte anyway into its own internal buffer using getc, so the assumption can be made it doesnít matter which one you use. But implementations of fread can vary because the standard doesnít really necessitate n * nmemb calls to getc. It may implement it completely differently if it wishes, as long as it follows the standard.

The number of getc calls is important because it makes a system call which is very expensive.
jmakin is online now   Reply With Quote
Old Yesterday, 05:43 PM   #36354
jjshabado
Carpal Tunnel
 
jjshabado's Avatar
 
Join Date: Jul 2006
Posts: 22,340
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

I get a lot of the recent complaints about SO, but this is like a perfect example of where itís good. The weird super edge case debate gets moved to the side / hidden and what you need to know is obvious.

Itís far from perfect (especially culturally), but damn am I glad it exists.
jjshabado is offline   Reply With Quote
Old Yesterday, 05:51 PM   #36355
microbet
Solar Powered
 
microbet's Avatar
 
Join Date: Jan 2005
Location: SoCal
Posts: 50,453
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Thanks jmakin
microbet is offline   Reply With Quote
Old Yesterday, 09:11 PM   #36356
jmakin
 
jmakin's Avatar
 
Join Date: Jan 2008
Location: Streaming
Posts: 29,160
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

I wrote a decently sized application in C today and my brain is absolutely fried, i came across that comment and i guess it triggered me more than it should have
jmakin is online now   Reply With Quote
Old Yesterday, 11:47 PM   #36357
RustyBrooks
Carpal \'Tunnel
 
RustyBrooks's Avatar
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 23,964
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Quote:
Originally Posted by jmakin View Post
Ok maybe i am just being nitpicky. I always tend to call with (n,1).
When you do it this way you can't tell how many bytes were read when it fails, which is sometimes useful to know
RustyBrooks is offline   Reply With Quote
Old Yesterday, 11:54 PM   #36358
RustyBrooks
Carpal \'Tunnel
 
RustyBrooks's Avatar
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 23,964
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Also, this is going out on a limb a bit, but I think POSIX specifies that fread should be an equivalent set of fgetcs. If you have a POSIX compiler, then it should always do that.

Not all compilers are POSIX compliant, and I wouldn't be surprised to find that some supposedly POSIX compliant compilers could have bugs or deviations from spec.

A few days ago I realized that stdc++ and libc++ have different behavior for a function, streambuff::in_avail, that tells you whether or not a stream has bytes that can be read. I can't remember which is which now, but in one of them, the function always says "no" even if the answer is "yes"

A program that we download/compile started breaking for us because they switched from one to the other.
RustyBrooks is offline   Reply With Quote
Old Yesterday, 11:56 PM   #36359
jmakin
 
jmakin's Avatar
 
Join Date: Jan 2008
Location: Streaming
Posts: 29,160
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Quote:
Originally Posted by RustyBrooks View Post
When you do it this way you can't tell how many bytes were read when it fails, which is sometimes useful to know


Yea i know, but the reads iím doing i want all or nothing
jmakin is online now   Reply With Quote
Old Today, 02:37 AM   #36360
microbet
Solar Powered
 
microbet's Avatar
 
Join Date: Jan 2005
Location: SoCal
Posts: 50,453
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

You can do this

Code:
function getValues(param) {
  let x = param + 2;
  let y = param + 3;
  let z = param + 4;
  return [x, y, z];
}

a = getValues(2);
alert(a[0]);  //4
alert(a[1]);  //5
alert(a[2]);  //6
Is there a way to do like this and just assign the return to variables in javascript? Seems like there might be some way to fat arrow something.

Code:
function getValues(param) {
  let x = param + 2;
  let y = param + 3;
  let z = param + 4;
  return x, y, z;
}

(a, b, c) = getValues(2);
(that doesn't work)

you can do this in python

Code:
def getValues(param):
   x = param + 2
   y = param + 3
   z = param + 4

(a, b, c) = getValues(2)
print(a)  #4
print(b)  #5
print(c)  #6
microbet is offline   Reply With Quote
Old Today, 03:50 AM   #36361
fredd-bird
Carpal \'Tunnel
 
fredd-bird's Avatar
 
Join Date: Aug 2007
Location: KG
Posts: 19,210
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

What you're looking for there is destructuring which is something that got added fairly recently in JS.

If we return that array of values, then we can destructure that into another array with those variables. Like this:
Code:
function getValues(param) {
    let x = param + 2;
    let y = param + 3;
    let z = param + 4;
    return [x, y, z];
}

let [ a, b, c ] = getValues(2);
console.log(a) 
console.log(b) 
console.log(c)

If you return an object like this, you can destructure it with this syntax. Note that your variable names on the left must match the variable names in the return value, since the return object actually looks like this: { x: 6, y: 7, z: 8 }
Code:
function retValues(param) {
    let x = param + 2;
    let y = param + 3;
    let z = param + 4;
    return { x, y, z };
}


let { x, y, z } = retValues(4) 
console.log(x)
console.log(y)
console.log(z)
fredd-bird is offline   Reply With Quote
Old Today, 04:10 AM   #36362
ChrisV
Carpal \'Tunnel
 
ChrisV's Avatar
 
Join Date: Jul 2004
Location: Adelaide, Australia
Posts: 38,167
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

You could just return them as properties on an object also. That way they have names.
ChrisV is offline   Reply With Quote

Reply
      

Thread Tools
Display Modes

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


Forum Jump


All times are GMT -4. The time now is 08:47 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright © 2008-2017, Two Plus Two Interactive
 
 
Poker Players - Streaming Live Online