No language would cache that unless they have a way to designate functions as deterministic (a given parameter always returns the same value).
This is not the case with the majority of code, since you usually aren't talking about functions in the mathematical sense but in the "check this string, whooops not deterministic" or have any kind of side effect that changes state.
Use a variable.
That's what I figured, I just didn't know if it was a thing where it could a variable and not modified, but I guess how does it know .find() is non-destructive.
So here's a weird thing that happened in the same place I noticed that thing.
One of the databases my corporate phone book site was using got moved to a different server. Since the actual initial source of the data had recently changed, some of the structure of the table I used also changed.
One of the changes that two columns, specialty1 and specialty2, were now just specialties, delimited by commas.
So I just use string.split and it works.
Another column, degree, is for some reason now degrees. So instead MD or DDS, it might have several, sometimes different, sometimes just MD, MD, MD, MD, MD. I guess one for each they received.
So I try string.split on that, and it just returns the whole string.
Used the same delimiter set of just a comma both times.
No language would cache that unless they have a way to designate functions as deterministic (a given parameter always returns the same value).
This is not the case with the majority of code, since you usually aren't talking about functions in the mathematical sense but in the "check this string, whooops not deterministic" or have any kind of side effect that changes state.
Use a variable.
In theory an optimizing compiler could catch that.
In practice, don't trust the optimizer to do anything more than precalculate arithmatic expressions. Measure performance with a profiling tool.
Does the (any/some/most?) compiler see all those identical calls to find and just put them in a variable to use as needed or does it do it each time?
It depends on the language, but I don't think I've ever really seen them cache stuff like that.
I think that any reasonably advanced compiler would probably catch that with common subexpression elimination/hoisting optimizations, especially if the string and the find function were designated const.
CSE/value hoisting is a pretty ancient optimization technique. If the compiler has enough information to know that the find function won't cause side-effects when it's called, then the find calls will almost certainly be hoisted (assuming the compiler doesn't suck and some level of optimization is enabled).
gavindelThe reason all your softwareis brokenRegistered Userregular
Praise the light, my newest graphics project uses openGL. Here's to hoping that leads to a much easier assignment.
Does anyone know how to set up a text input box in GL, GLU, or GLUT? The project requires that when the user presses 'N' that they get asked to provide a filename. I have the keybind working fine, but I can't find the function or mechanism for having a text pop up or input.
Oh, sure, but where's the fun in that? I never coded in Lisp, but every once in a while I like to imagine what it might be like. (I fiddled with emacs config way back when, but that doesn't really count)
Praise the light, my newest graphics project uses openGL. Here's to hoping that leads to a much easier assignment.
Does anyone know how to set up a text input box in GL, GLU, or GLUT? The project requires that when the user presses 'N' that they get asked to provide a filename. I have the keybind working fine, but I can't find the function or mechanism for having a text pop up or input.
None of those will do that. GL/GLU doesn't even really know about windowing. GLUT is pretty much output/window management only. Does it have to be OS-independent?
Praise the light, my newest graphics project uses openGL. Here's to hoping that leads to a much easier assignment.
Does anyone know how to set up a text input box in GL, GLU, or GLUT? The project requires that when the user presses 'N' that they get asked to provide a filename. I have the keybind working fine, but I can't find the function or mechanism for having a text pop up or input.
None of those will do that. GL/GLU doesn't even really know about windowing. GLUT is pretty much output/window management only. Does it have to be OS-independent?
I have no idea. Suppose I'll ask the professor on Tuesday. His prompt only says "This command loads all the data and parameters from a text file. Hitting the "n" key should prompt the user for the name of the file.", so maybe I'm barking up the wrong tree.
Anyone know if there's an API or something that I could call to get a list of purchased games of a particular steam user? I kinda want to make a randomizer that looks at all of your Steam games and randomly chooses 1-10 of them and you have to play it. Nothing fancy or anything just a fun little pet project but I can only find their Web API stuff which looks to let me link their steam login stuff to their site. Not quite what I was looking for... Didn't we have a PAer that made Steam signatures?
My brain is cramping from trying to figure out this assignment on figuring out the number of days old you are based on your birth date and the current day. The wife is knee deep in real coding work and master's degree homework so I don't wanna bother her.
I think I need to step away from it and hopefully make heads or tails of it later. Even looking at what other people did to solve isn't helping.
Need a voice actor? Hire me at bengrayVO.com
Legends of Runeterra: MNCdover #moc
Switch ID: MNC Dover SW-1154-3107-1051 Steam ID Twitch Page
As with any programming problem, try to break it up.
You're asked to find the number of days difference between two dates, so first of all, try calculating the number of days from 0 that a given date has.
Breaking that up, you would calculate all the days for previous years, then add all the days for previous months, then the days for the current month
# calc # of days for all years up to and including y
def yday(y):
return y * 365 + (y / 4) - (y / 100) + (y / 400)
def day_number(y, m, d):
d += yday(y - 1) # days for previous years
months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if(m > 2 and y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)):
d+=1 # if a leap year and past feb, add the leap day
for i in range(m-1):
d += months[i] # add in previous months
return d
def daysBetweenDates(year1, month1, day1, year2, month2, day2):
##
# Your code here.
##
return day_number(year2, month2, day2) - day_number(year1, month1, day1)
My brain is cramping from trying to figure out this assignment on figuring out the number of days old you are based on your birth date and the current day. The wife is knee deep in real coding work and master's degree homework so I don't wanna bother her.
I think I need to step away from it and hopefully make heads or tails of it later. Even looking at what other people did to solve isn't helping.
Well the real world answer is "use a well established datetime library".
While racing light mechs, your Urbanmech comes in second place, but only because it ran out of ammo.
As with any programming problem, try to break it up.
You're asked to find the number of days difference between two dates, so first of all, try calculating the number of days from 0 that a given date has.
Breaking that up, you would calculate all the days for previous years, then add all the days for previous months, then the days for the current month
The wife asked me to write out how I'd to it in a real-world scenario before creating any code. After doing so, I'm then supposed to transpose that into code.
I know that I'll need to create a leapYearCheck procedure, which I did like so:
def leapYearCheck(year1):
if year1 == 0:
return False
if year1 % 4 == 0:
if year1 % 100 == 0:
if year1 % 400 == 0:
return True
else:
return False
return True
return False
Now I've got a True/False check ready for the procedure calculating days. So I'm trying to wrap my head around making an efficient way to store the days in each month. My first thought was creating 12 variables, one for each month, and assigning them the proper day count. This is messy and a nightmare.
Looking at your code, I can see that there's an easier way of getting the answer with lists and for loops, but I don't know how they work yet and I'm trying to solve this without using stuff that hasn't been introduced yet.
Need a voice actor? Hire me at bengrayVO.com
Legends of Runeterra: MNCdover #moc
Switch ID: MNC Dover SW-1154-3107-1051 Steam ID Twitch Page
I'd say, figure out how to do it without the leap year first.
Leap year is an insignificant detail to the procedure.
The best way to store the date is an array of ints corresponding to the day count.
0-11, take the month's 'value' as an integer, subtract 1, and boom you've got your day count for each month.
Once you've worked out how to get the total days without factoring in the leap year, then you can progress to it.
I know a lot of courses grade on a pass/fail mechanism, but to me, I'd like to see your process on how you got there, and how you're doing it in code. I mean the assignment is pretty much titled "thinking critically."
tl;dr - ignore leap year for now, get it working with your total days in each month calculations first.
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
My brain is cramping from trying to figure out this assignment on figuring out the number of days old you are based on your birth date and the current day. The wife is knee deep in real coding work and master's degree homework so I don't wanna bother her.
I think I need to step away from it and hopefully make heads or tails of it later. Even looking at what other people did to solve isn't helping.
Well the real world answer is "use a well established datetime library".
Had my review today.
Apparently I need to make a more concerted effort to learn/use C++ though (investigating/fixing defects, working forward on new stuff coming down the pipe, etc), and I was basically told it would be a waste for me to focus on automation only (bye bye perl!)
My manager is actually pretty happy with where I am now and where I'm headed it seems. He just wants to make sure I'm focusing on the right areas.
So pretty good, all told.
crimsoncoyote on
+6
gavindelThe reason all your softwareis brokenRegistered Userregular
Dammit, Euclid, stop having already proved what I just proved.
Looks like we're either going to induce or break her water and go from there. As long as no one rebases we should be good! I'll post more in the days to come.
Posts
That's what I figured, I just didn't know if it was a thing where it could a variable and not modified, but I guess how does it know .find() is non-destructive.
So here's a weird thing that happened in the same place I noticed that thing.
One of the databases my corporate phone book site was using got moved to a different server. Since the actual initial source of the data had recently changed, some of the structure of the table I used also changed.
One of the changes that two columns, specialty1 and specialty2, were now just specialties, delimited by commas.
So I just use string.split and it works.
Another column, degree, is for some reason now degrees. So instead MD or DDS, it might have several, sometimes different, sometimes just MD, MD, MD, MD, MD. I guess one for each they received.
So I try string.split on that, and it just returns the whole string.
Used the same delimiter set of just a comma both times.
In theory an optimizing compiler could catch that.
In practice, don't trust the optimizer to do anything more than precalculate arithmatic expressions. Measure performance with a profiling tool.
Top 5: C, Java, Obj-C, C++, C#, PHP.
So there's that.
I think that any reasonably advanced compiler would probably catch that with common subexpression elimination/hoisting optimizations, especially if the string and the find function were designated const.
CSE/value hoisting is a pretty ancient optimization technique. If the compiler has enough information to know that the find function won't cause side-effects when it's called, then the find calls will almost certainly be hoisted (assuming the compiler doesn't suck and some level of optimization is enabled).
In programming we have two kinds of problems, cache invalidation, naming, and off by one errors
Does anyone know how to set up a text input box in GL, GLU, or GLUT? The project requires that when the user presses 'N' that they get asked to provide a filename. I have the keybind working fine, but I can't find the function or mechanism for having a text pop up or input.
Next version of NARS is in development. Here's a look!
Those brackets are, from the outside in:
- function call
- object for function arguments (in this case we're only using two, but there's more optional parameters than we use here)
- one of the arguments is an array of bits of dialog to show
- the array contains objects -- again, in this case case we're only using one, but the dialog elements can also have a header or an image
- the object contains a translated string
so while it may seem like a lot, they all have a purpose -- but when we're doing the simplest-possible version of this function, it looks a bit goofy.It looks much more manageable with a bit more formatting:
None of those will do that. GL/GLU doesn't even really know about windowing. GLUT is pretty much output/window management only. Does it have to be OS-independent?
I have no idea. Suppose I'll ask the professor on Tuesday. His prompt only says "This command loads all the data and parameters from a text file. Hitting the "n" key should prompt the user for the name of the file.", so maybe I'm barking up the wrong tree.
Ah. Damn it looks like I need to get a Web API key, which means I need a domain.
I think I need to step away from it and hopefully make heads or tails of it later. Even looking at what other people did to solve isn't helping.
Legends of Runeterra: MNCdover #moc
Switch ID: MNC Dover SW-1154-3107-1051
Steam ID
Twitch Page
You're asked to find the number of days difference between two dates, so first of all, try calculating the number of days from 0 that a given date has.
Breaking that up, you would calculate all the days for previous years, then add all the days for previous months, then the days for the current month
Well the real world answer is "use a well established datetime library".
The wife asked me to write out how I'd to it in a real-world scenario before creating any code. After doing so, I'm then supposed to transpose that into code.
I know that I'll need to create a leapYearCheck procedure, which I did like so:
Now I've got a True/False check ready for the procedure calculating days. So I'm trying to wrap my head around making an efficient way to store the days in each month. My first thought was creating 12 variables, one for each month, and assigning them the proper day count. This is messy and a nightmare.
Looking at your code, I can see that there's an easier way of getting the answer with lists and for loops, but I don't know how they work yet and I'm trying to solve this without using stuff that hasn't been introduced yet.
Legends of Runeterra: MNCdover #moc
Switch ID: MNC Dover SW-1154-3107-1051
Steam ID
Twitch Page
Leap year is an insignificant detail to the procedure.
The best way to store the date is an array of ints corresponding to the day count.
0-11, take the month's 'value' as an integer, subtract 1, and boom you've got your day count for each month.
Once you've worked out how to get the total days without factoring in the leap year, then you can progress to it.
I know a lot of courses grade on a pass/fail mechanism, but to me, I'd like to see your process on how you got there, and how you're doing it in code. I mean the assignment is pretty much titled "thinking critically."
tl;dr - ignore leap year for now, get it working with your total days in each month calculations first.
I guess you do know the way to San Jose, do do dooo dooo do do dooo dooo!
Apparently I need to make a more concerted effort to learn/use C++ though (investigating/fixing defects, working forward on new stuff coming down the pipe, etc), and I was basically told it would be a waste for me to focus on automation only (bye bye perl!)
My manager is actually pretty happy with where I am now and where I'm headed it seems. He just wants to make sure I'm focusing on the right areas.
So pretty good, all told.
@Ethea what's up
Remember: 90% of the cost of code is maintenance.
for what it's worth
NARS just put together this a few moments ago.
Probably completely random chance.
Right?