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 11-15-2018, 04:35 PM   #36351
goofyballer
 
goofyballer's Avatar
 
Join Date: Jun 2005
Posts: 64,961
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 11-15-2018, 04:56 PM   #36352
jmakin
 
jmakin's Avatar
 
Join Date: Jan 2008
Location: Streaming
Posts: 29,186
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Ok maybe i am just being nitpicky. I always tend to call with (n,1).
jmakin is offline   Reply With Quote
Old 11-15-2018, 05:03 PM   #36353
jmakin
 
jmakin's Avatar
 
Join Date: Jan 2008
Location: Streaming
Posts: 29,186
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 offline   Reply With Quote
Old 11-15-2018, 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 11-15-2018, 05:51 PM   #36355
microbet
Solar Powered
 
microbet's Avatar
 
Join Date: Jan 2005
Location: SoCal
Posts: 50,524
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Thanks jmakin
microbet is offline   Reply With Quote
Old 11-15-2018, 09:11 PM   #36356
jmakin
 
jmakin's Avatar
 
Join Date: Jan 2008
Location: Streaming
Posts: 29,186
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 offline   Reply With Quote
Old 11-15-2018, 11:47 PM   #36357
RustyBrooks
Carpal \'Tunnel
 
RustyBrooks's Avatar
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 23,965
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 online now   Reply With Quote
Old 11-15-2018, 11:54 PM   #36358
RustyBrooks
Carpal \'Tunnel
 
RustyBrooks's Avatar
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 23,965
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 online now   Reply With Quote
Old 11-15-2018, 11:56 PM   #36359
jmakin
 
jmakin's Avatar
 
Join Date: Jan 2008
Location: Streaming
Posts: 29,186
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 offline   Reply With Quote
Old 11-16-2018, 02:37 AM   #36360
microbet
Solar Powered
 
microbet's Avatar
 
Join Date: Jan 2005
Location: SoCal
Posts: 50,524
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 11-16-2018, 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 11-16-2018, 04:10 AM   #36362
ChrisV
Carpal \'Tunnel
 
ChrisV's Avatar
 
Join Date: Jul 2004
Location: Adelaide, Australia
Posts: 38,211
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
Old 11-16-2018, 11:03 AM   #36363
microbet
Solar Powered
 
microbet's Avatar
 
Join Date: Jan 2005
Location: SoCal
Posts: 50,524
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Thanks both.

I had heard someone talk about destructuring as a new feature in a JS podcast, but it was just talk, they don't really spell out code in podcasts. Now I know what they were talking about.

Chris, yeah. Either an object or array works, I was mostly curious, but the result goes in a very small function never to be used again and it seems more elegant to me to skip having to name the array or object.
microbet is offline   Reply With Quote
Old 11-18-2018, 01:49 PM   #36364
microbet
Solar Powered
 
microbet's Avatar
 
Join Date: Jan 2005
Location: SoCal
Posts: 50,524
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Quote:
Originally Posted by fredd-bird View Post
Skip Notepad++ and go straight to VS Code or get good at Vim.
I'm still splitting time on Notepad++ and Vim, but getting my .vimrc file set up better is making Vim nicer. I still need to get auto-completion.

(tabstop and shiftwidth=3, colorscheme evening, Lucinda_console font at 12 for my old eyes.)
microbet is offline   Reply With Quote
Old 11-18-2018, 02:40 PM   #36365
Victor
Carpal \'Tunnel
 
Victor's Avatar
 
Join Date: Jul 2003
Posts: 60,334
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Pretty sure you can use the array reduce function
Victor is offline   Reply With Quote
Old Today, 11:29 AM   #36366
stlows
centurion
 
Join Date: Apr 2016
Posts: 171
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

I have an interview for a job.

I have two years experience in .Net and the job is .Net, MVC, Web, Javascript, Scrum etc... standard stuff that I do regurlary.

They told me there is a 75 minutes test. What would be the best way to prepare for that kind of test? What are the generally asked question in those type of test?

Thanks
stlows is offline   Reply With Quote
Old Today, 11:31 AM   #36367
kerowo
lolcat
 
kerowo's Avatar
 
Join Date: Nov 2005
Posts: 35,649
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Check Glassdoor.com and see if they have anything on the tests during interviews.
kerowo is offline   Reply With Quote
Old Today, 01:29 PM   #36368
microbet
Solar Powered
 
microbet's Avatar
 
Join Date: Jan 2005
Location: SoCal
Posts: 50,524
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Quote:
Originally Posted by microbet View Post
I'm still splitting time on Notepad++ and Vim, but getting my .vimrc file set up better is making Vim nicer. I still need to get auto-completion.

(tabstop and shiftwidth=3, colorscheme evening, Lucinda_console font at 12 for my old eyes.)
omni-completion is pretty cool. I can see being able to really fly when you are good at it.
microbet 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 02:43 PM.


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