Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
tynam
May 14, 2007

Pie Colony posted:

Am I in any way crippling my career? Obviously it's not the worst thing to be constantly learning, but (1) I am learning a lot of cool theory and principles, but it's not like my next job will use any of those things, especially me only having a bachelor's with no plans to get a MS/PhD and (2) I'm missing out on a lot of "practical" knowledge about tool chains, build systems, deployment, testing, etc.

Since I have no idea what your career path is, here's some general advice.

Learn to properly build, maintain and use a relational database. It's probably the most useful thing I've picked up at my current job that's in demand everywhere and incredibly practical.

If you have plenty of downtime, keep plugging away at personal projects. You're essentially building up a portfolio to show off to new potential employers, and who knows, you might actually make money off of it on the side.

Study up on modern sdlc styles if you're worried about learning "tool chains, build systems, deployment, testing, etc". Most places do their own thing anyways so you'll never go into a job knowing everything up front.

Adbot
ADBOT LOVES YOU

an skeleton
Apr 23, 2012

scowls @ u
I mostly copied this from the internet and I know it works, but I don't understand how this function works. Number is an input that is asked for from the user.
code:
for (int i=1;i<=number;i++){
	System.out.print(fibonacciRecursion(i)+" ");
}

	}

	public static int fibonacciRecursion(int number){
	if(number==1||number==2){
		return 1;
	}
		return fibonacciRecursion(number-1) + fibonacciRecursion(number -2);
	
	}
}
How does fibonacciRecursion ever return anything besides 1? For example, if I enter 5 for the series and get:
1 1 2 3 5

Where do the 2, 3, 5 come from? It isn't fitting into my little squirrel brain.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Recursion can be hard to understand. Let's break it down for you.

Let's say the user enters the number 3. Then we'll call fibonacciRecursion(3).

if (number == 1 || number == 2). This is false as the number is not 1 or 2.

return fibonacciRecursion(number - 1) + fibonacciRecursion(number - 2);

expands to:

return fibonacciRecursion(2) + fibonacciRecursion(1);

Those, themselves, run in order. fibonacciRecursion(2) is 1, and fibonacciRecursion(1) both evaluate to 1, so it returns 1 + 1, or 2.

Make sure you understand this part before you read on. If you don't fully understand this part, the next one will confuse to no end. It's hard and it took me a few years to fully "grasp" recursion, so feel free to ask what may seem like silly questions if you still don't understand this half.

There's two "main" points of confusion I've seen while teaching: first, recursive algorithms can and will run infinitely if you don't program them properly. Note that there's a case where you don't call the function, which when the number is 1 or 2. As we're always counting down by 1 or 2, any valid input will hit this. This is known as the base case. Recursive algorithms without a base case will run infinitely or crash or do stupid things. There's no magic in the computer that will stop that from happening/

Second, every time you call a function, it gets a new location for variables that don't interfere with the old ones. They're still around, and will still be around with the same values when the "inner" functions complete.


OK, now let's say the user enters 5. fibonacciRecursion(5). This expands to:

fibonacciRecursion(4) + fibonacciRecursion(3)

We know that fibonacciRecursion(3) is 2 from above (although we could calculate it again, but that would waste space), so let's replace that right away.

fibonacciRecursion(4) + 2

And if we expand the remaining call, then we have:

(fibonacciRecursion(3) + fibonacciRecursion(2)) + 2

We've seen both of those before.

(2 + fibonacciRecursion(2)) + 2
(2 + 1) + 2

Thus, fibonacciRecursion(5) is indeed 5.

Suspicious Dish fucked around with this message at 01:57 on Jun 20, 2013

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
You really can't "cripple your career" in this industry. Well, not unless you do something like intentionally post your customers' credit card info to Reddit. Or you get prosecuted for assaulting your coworkers. Don't do these things.

It is possible to be a bad fit and have that come up in your first job. For example, if you are completely incompetent or personally abrasive or prone to starting/promulgating endless flame wars on internal mailing lists, then you have a tragic flaw which very well might cripple your career no matter where you go if you do not learn to cope. Or you can apply at Mozilla, which seems to collect at least the latter two categories.

It is also possible to get pigeon-holed into doing the same thing forever. Sometimes pigeons just accept the hole they got shoved into and never try to leave. Sometimes pigeons get comfortable in their hole and then convince themselves that they've forgotten how to fly. Sometimes pigeons don't realize when they're being offered a new hole. Sometimes pigeons badly want to try different holes but then just crap all over the place when it happens. Sometimes there's really only the one hole, and the best a pigeon can hope for in it is to either dig out their own little ribbon-filled crevice or to get assigned to watch the other pigeons — or to fly away.

Working at a "big name" isn't necessarily going to mean that the work is more interesting. It might mean that your work affects more people; on the other hand, it might also mean that you'll be more isolated from the people you affect. Or it might mean that you'll get stuck doing something completely unrelated to customers at all, just a cog in one monstrous machine — but that work might be incredibly interesting. It really depends on what motivates you.

Academia is really a very different subject, but if you are interested in a doctorate in a theory-heavy area, I can tell you straight off that nobody will care about a reference you get from your boss at a web-design company, unless it's one hell of an interesting company.

aerique
Jul 16, 2008
The Little Schemer is an awesome book to learn about recursion. Download Racket, get the book and if you've got the time you might get through it in two or three days. It's a small book focused at teaching one specific thing: recursion.

aerique fucked around with this message at 08:12 on Jun 20, 2013

the littlest prince
Sep 23, 2006


Pie Colony posted:

I'm working at my (first) job and I have a lot of downtime, partially because it's not challenging so I get it done fast and wait on testers, partially because there's not a real trend of rushing projects/ticket at the company. Anyway, I'm using the downtime to try to learn a lot about programming/comp sci. I am reading textbooks on stuff like PLT, automata theory, database theory, artificial intelligence, blah blah and sometimes (but less often - primarily since I don't have a lot of ideas for interesting stuff) programming small-medium sized projects (eso lang interpreters, AIs, etc).

Am I in any way crippling my career? Obviously it's not the worst thing to be constantly learning, but (1) I am learning a lot of cool theory and principles, but it's not like my next job will use any of those things, especially me only having a bachelor's with no plans to get a MS/PhD and (2) I'm missing out on a lot of "practical" knowledge about tool chains, build systems, deployment, testing, etc.

I feel like I could potentially get a job at some of the bigger names and work on something "interesting-enough" while still learning practical things. But I also don't want to be perpetually working on websites and GUIs, and I'd have to go through all the trouble of interviewing and getting time off and stuff which quite frankly is a real pain

e: honestly higher ed would be fantastic for me, but I didn't really make friends with any profs and have no idea how I could get 3 references - maybe one from a prof and one from a boss, idk. Also, this might sound kinda elitist but I really would like to study at a top school, so I feel references would be more important applying there.

Even if future jobs don't use those skills, and even if you're not that great at them, it still makes you look like a better candidate compared to those who don't.

If you want more hands-on experience without sacrificing personal time, you could ask your company (if you don't get written approval and you build something valuable it might come back to bite you) if they mind you working on personal projects during downtime. They might interpret this request in a bad way of course, depending on the culture. Else, stay the course, or use personal time for it.

an skeleton
Apr 23, 2012

scowls @ u

Suspicious Dish posted:

Recursion can be hard to understand. Let's break it down for you.

Let's say the user enters the number 3. Then we'll call fibonacciRecursion(3).

if (number == 1 || number == 2). This is false as the number is not 1 or 2.

return fibonacciRecursion(number - 1) + fibonacciRecursion(number - 2);

expands to:

return fibonacciRecursion(2) + fibonacciRecursion(1);

Those, themselves, run in order. fibonacciRecursion(2) is 1, and fibonacciRecursion(1) both evaluate to 1, so it returns 1 + 1, or 2.

Make sure you understand this part before you read on. If you don't fully understand this part, the next one will confuse to no end. It's hard and it took me a few years to fully "grasp" recursion, so feel free to ask what may seem like silly questions if you still don't understand this half.

There's two "main" points of confusion I've seen while teaching: first, recursive algorithms can and will run infinitely if you don't program them properly. Note that there's a case where you don't call the function, which when the number is 1 or 2. As we're always counting down by 1 or 2, any valid input will hit this. This is known as the base case. Recursive algorithms without a base case will run infinitely or crash or do stupid things. There's no magic in the computer that will stop that from happening/

Second, every time you call a function, it gets a new location for variables that don't interfere with the old ones. They're still around, and will still be around with the same values when the "inner" functions complete.


OK, now let's say the user enters 5. fibonacciRecursion(5). This expands to:

fibonacciRecursion(4) + fibonacciRecursion(3)

We know that fibonacciRecursion(3) is 2 from above (although we could calculate it again, but that would waste space), so let's replace that right away.

fibonacciRecursion(4) + 2

And if we expand the remaining call, then we have:

(fibonacciRecursion(3) + fibonacciRecursion(2)) + 2

We've seen both of those before.

(2 + fibonacciRecursion(2)) + 2
(2 + 1) + 2

Thus, fibonacciRecursion(5) is indeed 5.


Ok, I think I get it, so it's always just a bunch of 1's added up from the if number == 1 case? Thanks for the excellent explanation

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Well, you have to think about what everything expands to. Since fibbonacciRecursion(5) is so long to type, let's just use f(5)

f(5) = f(4) + f(3)
f(5) = f(4) + (f(2) + f(1))
f(5) = f(4) + (1 + 1)
f(5) = (f(3) + f(2)) + (1 + 1)
f(5) = ((f(2) + f(1)) + f(2)) + (1 + 1)
f(5) = (((1 + 1) + 1) + (1 + 1)

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


The Fibonacci case is a little bit complicated because you have the double recursive call. Instead let's look at the factorial function, which is a little simpler. I'm

The standard implementation is a loop like so:
code:
int factorial(int n)
{
  fact = 1
  for (i = 0; i <= n; i++)
  {
    fact = fact * i
  }
  return fact
}
However, you can also give a recursive implementation:
code:
int factorial(int n)
{
  if (n == 0)
  {
    return 1
  }
  return n * factorial(n - 1)
}
Here I think it's easy to see that the iterative and recursive implementations are equivalent. The reason that we use recursion is because it's often not so straightforward to convert a recursive definition into an iterative implementation. If you want a nice exercise, think of how to write an iterative implementation of the Fibonacci function.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Just to nitpick but your factorial function isn't checking for a negative input.

Pseudo-God
Mar 13, 2006

I just love oranges!

Hard NOP Life posted:

Just to nitpick but your factorial function isn't checking for a negative input.
It's sufficient to explain the concept. There are many things the input does not check, such as whether it's a floating point, a string, or totally something else.

JawnV6
Jul 4, 2004

So hot ...

Hard NOP Life posted:

Just to nitpick but your factorial function isn't checking for a negative input.
It'll wrap eventually.

Pseudo-God posted:

It's sufficient to explain the concept. There are many things the input does not check, such as whether it's a floating point, a string, or totally something else.
Just how little faith are you putting into the type system?

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Hard NOP Life posted:

Just to nitpick but your factorial function isn't checking for a negative input.

It's teaching code, not production code. Error checking gets in the way of illustrating the point.

Pseudo-God
Mar 13, 2006

I just love oranges!

JawnV6 posted:

Just how little faith are you putting into the type system?
cin in C++ required a ton of boilerplate to make sure the input was properly handled. Thankfully, I don't use C++ anymore.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Right, but that's a method with a given type signature, you can't pass in a string or a floating point. The reading of the input is totally separate from the definition of the function.

And while I appreciate that it's just an example, I think it's also important to show what can happen if you're not careful with a recursive function. Luckily this one will eventually wrap like Jawn said but other examples could lead to an infinite recursion.

shrughes
Oct 11, 2008

(call/cc call/cc)
Infinite recursion and a stack overflow or a CPU spinning are okay failure cases. If you checked for negative input you'd just want to abort the process anyway. You aren't checking if the input value is greater than 12 either.

1337JiveTurkey
Feb 17, 2005

An example of recursion which I prefer is finding the size of all the files underneath a specified directory. It's less abstract and the directory tree structure really lends itself to recursion.

Finding the size of a file by itself is really easy because there's a built in function in whatever language you're using for that. In Java if you've got a File object that corresponds to a filesystem file then all you do is call file.length(). If it's not then it might be a special file which doesn't actually take up any space on the disk or it might be a directory. For a directory you just add up the sizes of everything inside of it. We could sit there and spell out again how to find the size of everything inside of that but we've already got how to do that written out.

code:
static long fileSize(File file) {
	if (file.isFile()) {
		return file.length();
	}
	else if (file.isDirectory()) {
		long sum = 0L;
		for (File child : file.listFiles()) {
			sum += fileSize(child);
		}
		return sum;
	}
	else {
		// Some sort of special file I give no fucks about
		return 0L;
	}
}
Intuitively this seems like it shouldn't work because when we have the code call itself, aren't we already using file and sum and the list of children? If you ever get stuck writing absolutely ancient FORTRAN or COBOL code, that's exactly what happens because there's one file and one sum and that's it. More modern languages use activation records which are disposable scratchpads. Each time you call fileSize, it makes a new place to put all the variables that you're using which doesn't clobber the existing values. Call it all you want, the system will just make a new scratchpad area each time.

To get an idea of how a computer really does this, it helps to get a chalkboard and a laptop. Start in a directory of your choice and then just start adding up the file sizes, using the leftmost part of the chalkboard as a scratchpad. When you run into a subdirectory, write down the name of where you are in the current directory so you don't lose track of your spot, draw a line to the right of where you've been keeping count and just start adding up the file sizes in that directory. Now start adding up the files in that directory doing the exact same thing.

Whenever you hit another subdirectory, draw another line and repeat the process. When you actually finish a directory, take that tally and add it to the count to the left and then erase everything to the right of the line since you don't need it any more. Now just pick up where you left off in that directory until you hit the end of it and take its tally and add it to the count to the left and so on. When you've finished the directory all the way on the left, you're done.

omeg
Sep 3, 2012

Just remember that in reality "directory size" can be a very nebulous concept. With file systems supporting sparse files, softlinks, hardlinks, network shares and even loops it can be dangerous to do something like calculating directory size.

armorer
Aug 6, 2012

I like metal.

shrughes posted:

Infinite recursion and a stack overflow or a CPU spinning are okay failure cases. If you checked for negative input you'd just want to abort the process anyway. You aren't checking if the input value is greater than 12 either.

A stack overflow can be avoided in a lot of languages by reworking the code a bit to use tail call optimization. The mantra of "leave no work left to be done" is a good one to know if you are writing any recursive code.

The factorial example given earlier is "bad" (no offense!) because it does all the work out the way out. This will overflow the stack with a sufficiently large input.

code:
int factorial(int n)
{
  if (n == 0)
  {
    return 1
  }
  return n * factorial(n - 1)
}
A safer implementation which uses tail call optimization will do the work on the way in instead:

code:
int factorial(int n)
{
  return factorialHelper(n, n-1)
}

int factorialHelper(int accumulator, int n)
{
  if(n == 1)
  {
    return accumulator
  }
  
  return factorialHelper(accumulator * n, n-1)
}
Notice that in this implementation, each calling function immediately returns the result of the subroutine call. It "leaves no work to be done" after the subroutine is called. In many languages, this will result in compiled code that does not create stack frames as recursive calls are made, and thus can handle arbitrarily large inputs. See the wikipedia article for more details.

-----
Disclaimer: That is "browser code" that I didn't try to run. I think it conveys the general idea though. I am also being lazy and not checking my inputs.

Bunny Cuddlin
Dec 12, 2004
Earlier I actually considered posting, as a joke, that we give this new programmer who didn't understand recursion a lesson on tail call optimization, stack overflows, lamdba calculus, etc. Looks like it wouldn't have been a very good joke.

shrughes
Oct 11, 2008

(call/cc call/cc)

armorer posted:

A stack overflow can be avoided in a lot of languages by reworking the code a bit to use tail call optimization. The mantra of "leave no work left to be done" is a good one to know if you are writing any recursive code.

You'd then just write iterative code, because in any language without explicit tail call syntax (seen in early versions or proposals of Java, and SysRPL of all things), relying on the compiler to do tail call optimization or the runtime to tail call eliminate is an act that introduces fragility into your system.

shrughes fucked around with this message at 21:29 on Jun 21, 2013

armorer
Aug 6, 2012

I like metal.

Bunny Cuddlin posted:

Earlier I actually considered posting, as a joke, that we give this new programmer who didn't understand recursion a lesson on tail call optimization, stack overflows, lamdba calculus, etc. Looks like it wouldn't have been a very good joke.

Tail call optimization isn't very complicated, and if you are just learning recursion it's good to learn it so you don't get into bad habits. And as for relying on it: If you are writing recursive code in a language that supports it, and the solution allows for it, then do it. It is that easy. If you are writing recursive code in a language that doesn't support it, then you should think really hard about whether or not there is a better solution.

LiterallyAnything
Jul 11, 2008

by vyelkin
This might be more of a system admin question than a VB question but I think this is an appropriate place to ask-

I have a VB script that copies files and pushes them out to computers on the network, but the files on the destination machine don't seem to retain the original's permissions... All machines involved are Windows 7. Anyone have a quick guess as to why this might be?

Mr. Crow
May 22, 2008

Snap City mayor for life
How insanely difficult (or not) would it be to program a robot to move around predefined space to predefined points autonomously?

We're doing a side project at work to have something happen when someone breaks a build, I think it would be cool to have some sort of "robot" drive around the office to said persons office and... do something.

I have never done anything remotely like this before so I don't even know where to look or how feasible it is. I realise it would probably take a long time to get it working.

Zhentar
Sep 28, 2003

Brilliant Master Genius
It's perfectly feasible; there are many different approaches that can work well for that sort of thing. It's going to be a lot of work and learning if you've never done anything with robotics before, though.

Hypnobeard
Sep 15, 2004

Obey the Beard



Brady posted:

This might be more of a system admin question than a VB question but I think this is an appropriate place to ask-

I have a VB script that copies files and pushes them out to computers on the network, but the files on the destination machine don't seem to retain the original's permissions... All machines involved are Windows 7. Anyone have a quick guess as to why this might be?

Not sure it's changed in Win7, but generally in Windows the files will inherit the permission of their parent object (i.e., the containing folder at the destination) when copied or moved, unless the move occurs on the same volume, in which case they will retain the original permissions.

If you're just calling copy or something to do the copying, trying using xcopy instead; you can use the /o switch to copy the DACL and the /x switch to copy the SACL (which also includes the DACL).

Hoops
Aug 19, 2005


A Black Mark For Retarded Posting
Anyone do a lot with R? I need a graphics package that will allow me to annotate a 3-d graph of a function, with annotations at specific parts of the graph. My ideal would be a line coming off the graph at say a maximum point, to a text box that goes into more detail about the function at that point (might be asking too much for R).

If there's nothing like that then I can just create that visual in a different program, but I'd like something I adjust and play around with and still get the correct info on there.

bobua
Mar 23, 2003
I'd trade it all for just a little more.

Not sure if this is the best place for this but here goes...

I have a camera that only has linux\windows usb driver support for x86. I want to use it with an ARM board like a beagleboard. Would it be realistic to run something like qemu to get it working?

beagle -> ARM linux -> qemu -> x86 linux -> camera driver?

raminasi
Jan 25, 2005

a last drink with no ice

Hoops posted:

Anyone do a lot with R? I need a graphics package that will allow me to annotate a 3-d graph of a function, with annotations at specific parts of the graph. My ideal would be a line coming off the graph at say a maximum point, to a text box that goes into more detail about the function at that point (might be asking too much for R).

If there's nothing like that then I can just create that visual in a different program, but I'd like something I adjust and play around with and still get the correct info on there.

You might ask the scientific programming megathread.

tarepanda
Mar 26, 2011

Living the Dream
Are there any programming certifications worth getting? Japan loves certifications.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Yeah the Java ones

Polio Vax Scene
Apr 5, 2009



IIS Question:

Say I have two different web services, one at c:\apples, one at c:\bananas, and I want to have them both accessible from the same port. So typing apples.company.com into a web browser will pull up the apples service and the same with bananas and the bananas service.

Can I do this without assigning multiple ports? How about multiple sites?

What If I have one site at c:\fruit and need apples.company.com to point to c:\fruit\apples and bananas.company.com to point to c:\fruit\bananas?

Maybe there's a better thread to ask this in?

robostac
Sep 23, 2009
You'd probably do better in the webhosting megathread in sh/sc (http://forums.somethingawful.com/showthread.php?threadid=3289126)

The feature you are talking about is usually called vhosts . I don't know how it works in IIS

JawnV6
Jul 4, 2004

So hot ...
I have a noisy data set. I want to smooth it out. I started analytically and it was a mess of effects that I don't want to dig into so I took a bunch of readings and want to extract a smooth curve out of that. Averaging around each integer is still fairly noisy, what sort of algorithms or techniques should I look into?

nielsm
Jun 1, 2009



Is the data organised around a physical axis, e.g. time or space? If so you can use a simple gaussian kernel, like those used in image processing. (By gaussian kernel I mean a normal distribution function with rho chosen depending on how much smoothing you want.)

If your time (or distance) axis is on a discrete scale you can pre-calculate a series of coefficients to use in a weighted moving average. If the axis is continuous, you will have to calculate the coefficient for each data point for every point.
Also, if your data is not evenly distributed across the axis (distance between points varies), keep in mind you should probably be working with the distance and not the count of points to participate in each averaged point.

Oh yeah, and don't have every point participate in the average, limit it to a window unless you have plenty of time.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

JawnV6 posted:

I have a noisy data set. I want to smooth it out. I started analytically and it was a mess of effects that I don't want to dig into so I took a bunch of readings and want to extract a smooth curve out of that. Averaging around each integer is still fairly noisy, what sort of algorithms or techniques should I look into?

A simple recursive low-pass filter, like an exponential average, is very quick to implement. If that doesn't do the job you want, you can look at something like a windowed sinc.

JawnV6
Jul 4, 2004

So hot ...

Otto Skorzeny posted:

A simple recursive low-pass filter, like an exponential average, is very quick to implement.

Worked for me. Thanks!

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

It has been awhile since I made a windows GUI app. Is WPF the way to go, or is there a newer hotness? I will be using C#.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



I think WinRT is technically the newest hotness (sort of), but it can use the same XAML that a regular WPF app can. That said, you should probably go with WPF which is going to be more widely supported right now. You should also look up the (in my opinion terribly named) MVVM model because it actually does make WPF a lot easier to work with.

Adbot
ADBOT LOVES YOU

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

Thanks. WinRT looks a bit too new and hot for me (only Windows 8 AFAICT), so WPF it is.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply