The Big Programming Thread - Page 467
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
Manit0u
Poland17050 Posts
| ||
obesechicken13
United States10467 Posts
On April 13 2014 05:23 Nesserev wrote: Secondly, the Interface Segregation: So, basically, what it comes down to, is that in the first example, every method that is used by the clients is part of one big Service class. In the second example, every method that is used by a certain type of client, is put in a client specific class/interface. In the end, the Service class inherits all those specific classes/interfaces. Thanks for all the help guys. This part is still bugging me, shouldn't the client derive its functionality from some contract with the server/service? Because there is only one service and many clients. | ||
Nesserev
Belgium2760 Posts
| ||
obesechicken13
United States10467 Posts
On April 13 2014 11:29 Nesserev wrote: Well, that's what happens, the client derives its functionality from ITS contract with the server/service, BUT the service derives its interface from ALL of its contracts with clients. I'll try to explain this in an abstract way via browsers (client) and servers(service), but I only have a basic understanding of how browsers work, so I hope I don't make (m)any mistakes: Not all browsers support the same features, should this be a reason for all of them to use different services? For example: - All browsers are able to get pages, ofc. - Browsers A and B both support text - Browser A also supports images, while Browser B doesn't - Browser A doesn't support videos, but Browser B does So, the interfaces of browsers A and B should look like this: Browser A: getPage, getText, getImage Browser B: getPage, getText, getVideo The interfaces serverside for every client individually would be (these are separate classes, will function as base classes) Interface for A: sendPage, sendText, sendImage Interface for B: sendPage, sendText, sendVideo Now we unite those serverside interfaces into one service (Service class is derived from those base classes) Service : sendPage, sendText, sendImage, sendVideo I hope this helps a bit? DISCLAIMER: I'm tired; it's 4:XX am in the morning; I don't want a technical discussion like the one 20-30 pages ago about multiple inheritance and the "dreaded" diamond of dead, because I used an example to explain the concept and nothing more. I think this makes sense. I'm still trying to wrap my head around concrete classes inheriting from abstract classes and this whole dependency inversion principle. Every little bit helps. | ||
Manit0u
Poland17050 Posts
I'm aware that my if check is probably complete garbage and will have to change it but I have no idea why does it throw an error when assigning the value to dateCheck (I have code that does exactly the same thing in another class and it works flawlessly). Any help is appreciated. | ||
Ame
United States246 Posts
for (int i = 0; i < primeSieve.length; i++) It's where the slowdown occurs that confuses me. With a cap of around n = 400m, it starts to really slow down around primeSieve[i] ~ 350m. At this point primeSieve[i] is way larger than sqrt(400m), so all that should be happening is check if marked[i] is true/false (boolean array) and then adding it to primeList (ArrayList<Integer>, size() at {primeSieve[i] = 350m} around 19m, init to be such that it never needs to be resized). If I throw a 'print last prime' statement, it looks the program starts stuttering (prints out blocks of primes, freezes/waits about 5 seconds, prints out another block, etc) with the blocks printing out shrinking in size (towards the end before I stopped the program, it would only print out blocks of about 50 primes before freezing). Task Manager during runtime shows CPU usage ~99% and Physical Memory ~95% :| It works fine up to n = 350m, ~doubling in run time between n = 150m (15 seconds) and n = 350m (30 seconds). But at 400m it goes LOLNO and runs for over 5-10 minutes before I cut it off. During the 400m run it still spits out primes through 350m fairly quickly (under a minute) before afking past 350m. JVM ran with heap size arguments to handle arrays and ArrayList. Any idea what this might be or what I should be googling to find out more? Is this some crazy memory access thing? | ||
Millitron
United States2611 Posts
As for the weird printing, I think that's an artifact of system.out.print. Printing to the screen is horribly slow compared to doing math. | ||
Blisse
Canada3710 Posts
On April 14 2014 03:45 Manit0u wrote: Ok, I've run into some stupid C# problem. I'm a complete newbie with C# so please bear that in mind before laughing too hard:
I'm aware that my if check is probably complete garbage and will have to change it but I have no idea why does it throw an error when assigning the value to dateCheck (I have code that does exactly the same thing in another class and it works flawlessly). Any help is appreciated.
Your Date value is not being set. Should probably put a breakpoint there and check all your values to see if everything's what you expect.. | ||
Manit0u
Poland17050 Posts
| ||
whiteLotus
1833 Posts
| ||
cha0
Canada488 Posts
On April 14 2014 04:58 whiteLotus wrote: just a dumb question, is it theoretically possible to actually learn programming through google, various online courses and tutorials, like lets say java,php,jq, maybe some python or C, and actually get a job as a web programmer or smth at some shitty ass company, or you would still ideally need some university courses like advanced math and shit? i dont mean anything like software developer at Blizzard or anything like that lol. Anything is possible, even the word impossible is just saying "I'm possible" On a serious note, yes you can. It is hard and you'll need to have a lot of your own work to show to get noticed since most companies will always look for a degree but with a well maintained portfolio along with really knowing your stuff (Going through the online courses properly and not just skimming through them) you could learn to program and get webdev job. It won't be a walk in the park, but neither is finding a job even with a CS degree. | ||
spinesheath
Germany8679 Posts
On April 14 2014 04:58 whiteLotus wrote: just a dumb question, is it theoretically possible to actually learn programming through google, various online courses and tutorials, like lets say java,php,jq, maybe some python or C, and actually get a job as a web programmer or smth at some shitty ass company, or you would still ideally need some university courses like advanced math and shit? i dont mean anything like software developer at Blizzard or anything like that lol. You certainly can become good enough, the question is whether you can get an invitation to an interview. The majority of my knowledge is from the internet and books, university was a painful waste of time. Proof techniques, combinatorics and matrices are pretty much the only things I learnt at univeristy and consider relevant. For comp sci stuff, it was far more efficient to just read it up myself. But I don't know how good universities are where you live, and having a piece of paper saying "I provably spent some time on learning moderately relevant stuff" is rather effective for getting a job. | ||
Cyx.
Canada806 Posts
On April 14 2014 03:46 Ame wrote: So I'm running Sieve of Eratosthenes and notice it takes a big hit to speed (on my laptop, was 'average' about 5 years ago) as the number to search to rises. for (int i = 0; i < primeSieve.length; i++) It's where the slowdown occurs that confuses me. With a cap of around n = 400m, it starts to really slow down around primeSieve[i] ~ 350m. At this point primeSieve[i] is way larger than sqrt(400m), so all that should be happening is check if marked[i] is true/false (boolean array) and then adding it to primeList (ArrayList<Integer>, size() at {primeSieve[i] = 350m} around 19m, init to be such that it never needs to be resized). If I throw a 'print last prime' statement, it looks the program starts stuttering (prints out blocks of primes, freezes/waits about 5 seconds, prints out another block, etc) with the blocks printing out shrinking in size (towards the end before I stopped the program, it would only print out blocks of about 50 primes before freezing). Task Manager during runtime shows CPU usage ~99% and Physical Memory ~95% :| It works fine up to n = 350m, ~doubling in run time between n = 150m (15 seconds) and n = 350m (30 seconds). But at 400m it goes LOLNO and runs for over 5-10 minutes before I cut it off. During the 400m run it still spits out primes through 350m fairly quickly (under a minute) before afking past 350m. JVM ran with heap size arguments to handle arrays and ArrayList. Any idea what this might be or what I should be googling to find out more? Is this some crazy memory access thing? So wild guess - I might be really wrong - but on an old system with 2GB of RAM the max you'd be able to fit in RAM even with nothing else happening at all would be like 500 million ints or so, meaning that other things could reasonably eat up a couple hundred million of those spaces, leaving you with room for 300 million ints in memory before you started requiring a LOT of disk accesses, which would totally destroy your performance. | ||
Ame
United States246 Posts
On April 14 2014 04:29 Millitron wrote: I'm not familiar with the Sieve of Eratosthenes, but is it possible that at around 350m primeSieve is over 2 billion? If primeSieve rolls over, you're screwed and stuck in the second for loop forever. As for the weird printing, I think that's an artifact of system.out.print. Printing to the screen is horribly slow compared to doing math. Whoops, some clarity: by 350m primeSieve, I meant the integer is ~350,000,000, so not worried about overflow yet, at least I don't think. And yea, I've run into the system.out.print being slow a bit back when I noticed run time went from minutes to seconds or something ridic by cutting out printing during steps the first time I tried to throw together a prime generator. :p Still ran for over 5 minutes of nothing before I cut out without the print statements, so I don't think it was printing alone. I mainly threw in printing to make sure the ranges were still in values expected for the loop (checking for overflow) and to see where performance started taking a hit (the 350m figure). On April 14 2014 05:34 Cyx. wrote: So wild guess - I might be really wrong - but on an old system with 2GB of RAM the max you'd be able to fit in RAM even with nothing else happening at all would be like 500 million ints or so, meaning that other things could reasonably eat up a couple hundred million of those spaces, leaving you with room for 300 million ints in memory before you started requiring a LOT of disk accesses, which would totally destroy your performance. I had a vague notion that it might have been a reason like this, but before now haven't read too much into RAM vs disk access/etc.. With your guess I will be doing so now. + Show Spoiler [Ramblings] + Other details for fun: laptop system claims 4GB, but no idea how much of that Java can probably access. Having to use <Integer> in ArrayList instead of being able to use int probably adds decent bit of memory overhead, and other inefficiencies I have sound enough to push things out of RAM into disk anyways. Without some trickery (reading up on partitioned sieves and stuff), looks like I'm actually approaching the limit of how many primes I can generate gg. Original problem was actually just to check if a list of arbitrary large numbers were prime, so turns out using BigInteger.probablePrime() ending up being a way faster solution (well not really arbitrary and there's probably some really fancy mathematical way to do it, but math). Now just to code my own version of Miller Rabin, hue. | ||
bangsholt
Denmark138 Posts
On April 14 2014 04:42 Manit0u wrote: The thing is, the date was being set. I solved it by making the check in a different class though (before strings are joined with -). Why are you not converting the string date into a DateTime or something similar as soon as you can? You can always get the string representation at a later point - or even use Humanizer, if it's to show for a user. http://www.hanselman.com/blog/NuGetPackageOfTheWeekHumanizerMakesNETDataTypesMoreHuman.aspx | ||
Manit0u
Poland17050 Posts
On April 14 2014 05:23 spinesheath wrote: You certainly can become good enough, the question is whether you can get an invitation to an interview. The majority of my knowledge is from the internet and books, university was a painful waste of time. Proof techniques, combinatorics and matrices are pretty much the only things I learnt at univeristy and consider relevant. For comp sci stuff, it was far more efficient to just read it up myself. But I don't know how good universities are where you live, and having a piece of paper saying "I provably spent some time on learning moderately relevant stuff" is rather effective for getting a job. It all depends. I have a friend who quit uni because he couldn't be bothered with this kind of stuff and now is a top notch programmer working for big companies (Symantec, Oracle and such). What's most important in this business is the experience, nothing beats that. You can learn all you want from books/courses/studies but at the end of the day it all comes down to 'Are you experienced enough to do it without really thinking about it?'. That's the feeling I get when I'm asking my friends who are established programmers for some help. They're able to solve the problems that take me several hours in 5 minutes and do it way more efficiently and elegantly than I could ever hope to do now. Because they all have 10+ years in doing this stuff under their belts they know the realities, all the design patterns and best ways to do things inside out. I'm pretty much in your position right now. I want to change my job and move to a completely different sector. I know some general OOP, I understand the code pretty well and can do most of the basic/intermediate stuff in any of the C-family languages (C, C#, C++, Java, PHP, Python, LPC - I did some minor freelance stuff in all of them) but getting a real job is a different story entirely. Stuff you MUST know (because that's what they'll ask you for in 90% of job interviews even for an internship): - at least one framework (in case of PHP/Python) - UML and design patterns - at least one version control system (git and svn are the most common) - pretty good overall knowledge of the language, associated libraries etc. - in case of PHP/Python they'll also require some knowledge of JS/CSS/HTML most of the time and SQL every time During my interviews I've found out that they're not really interested in 'if you can do it' but rather 'if you can do it the way they want you to'. That's actually a lot of stuff to learn by yourself, but it's doable if you don't go too broad (like I did) but instead pick something popular and go deep with that first, branching out will be easier when you've mastered it. For PHP/webdev you would need: 0. General PHP - including PDO, MVC and OO stuff in PHP 1. Zend framework - pretty popular and relatively easy to get into, unlike say Symfony 2. MySQL - databases are a must 3. Some JS/CSS/HTML - CSS/HTML are pretty easy, JS shouldn't be much of a trouble if you get a hang on PHP 4. GIT 5. Design patterns for PHP This package should get you a job no problem. After the first job it should be easier since you'll be able to score some experience and build up your portfolio. Just some food for thought. | ||
CatNzHat
United States1599 Posts
On April 14 2014 04:58 whiteLotus wrote: just a dumb question, is it theoretically possible to actually learn programming through google, various online courses and tutorials, like lets say java,php,jq, maybe some python or C, and actually get a job as a web programmer or smth at some shitty ass company, or you would still ideally need some university courses like advanced math and shit? i dont mean anything like software developer at Blizzard or anything like that lol. Not a dumb question, and it is most certainly possible as I did it myself. Ideally you would take some math and data structures/algorithms courses (as I did at a local junior college). I'm working alongside some ivy league graduates (Cornell), we get paid on the same scale. As far as working for Blizzard or other corporate companies it's just a bit trickier to get started. For the last 5 years I've worked at startups around the bay area, so it's easier for me to get interviews at other startups than at big companies like Google/Apple/LinkedIn. You absolutely need to know your data structures and algorithms to be a successful software engineer anywhere. Learning languages, frameworks and APIs is secondary to that. I've done phone screens with a ton of engineers with good looking resumes that list relevant technologies, but then when I ask them a stupidly simple question (like what's the difference between a stack and a queue, or hash vs array) and they can't come up with anything. If you really think that you want to be a software engineer then I recommend you find an intro to CS class online (I think UC Berkeley has published a video version of theirs, as has MIT). Follow along with every exercise, use google to figure out how things work if you don't understand, and then find yourself the data structures and algorithms class and do the same. After if you're still interested you should have a better idea of a direction you want to go, and some things that you want to learn. If you're leaning to the web side then take a class on databases. There's a lot to learn there about mapping out an application to a relational database, and how to ensure performance and scalability. You should be able to build yourself a neat little Rails/Django/Express app afterwards, maybe integrate with some web APIs. If you're really engaged with this then you'll probably find yourself wanting to learn more about javascript, one of the better books to read on the subject is Douglas Crockford's Javascript: The good parts. If you're interested in the mobile application development side then find a class on objective C or java for android and build yourself a neat little app. I'd recommend you test cover your personal projects, you'll force yourself to write better code (untestable code is bad code) and when you go to show it off in an interview you'll get big bonus points. I've interviewed people who say they like testing and have experience with TDD, but then show us personal projects with zero test coverage. It's a big turn off to see someone talk the talk but not walk the walk, and even more so since we require everyone to test cover their code. TL;DR: Yes, I did it. | ||
LaNague
Germany9118 Posts
On April 14 2014 04:58 whiteLotus wrote: just a dumb question, is it theoretically possible to actually learn programming through google, various online courses and tutorials, like lets say java,php,jq, maybe some python or C, and actually get a job as a web programmer or smth at some shitty ass company, or you would still ideally need some university courses like advanced math and shit? i dont mean anything like software developer at Blizzard or anything like that lol. i dont know how it is in other countries, but "programmer" is actually not a university profession in germany, its an apprenticeship thing on a school level. You can learn programming with books for sure, i did when i was a kid. But the whole design part and scientific thinking that you need for complex problems is hard to aquire without someone teaching you. | ||
misirlou
Portugal3227 Posts
On April 14 2014 06:03 Ame wrote: Whoops, some clarity: by 350m primeSieve, I meant the integer is ~350,000,000, so not worried about overflow yet, at least I don't think. And yea, I've run into the system.out.print being slow a bit back when I noticed run time went from minutes to seconds or something ridic by cutting out printing during steps the first time I tried to throw together a prime generator. :p Still ran for over 5 minutes of nothing before I cut out without the print statements, so I don't think it was printing alone. I mainly threw in printing to make sure the ranges were still in values expected for the loop (checking for overflow) and to see where performance started taking a hit (the 350m figure). I had a vague notion that it might have been a reason like this, but before now haven't read too much into RAM vs disk access/etc.. With your guess I will be doing so now. + Show Spoiler [Ramblings] + Other details for fun: laptop system claims 4GB, but no idea how much of that Java can probably access. Having to use <Integer> in ArrayList instead of being able to use int probably adds decent bit of memory overhead, and other inefficiencies I have sound enough to push things out of RAM into disk anyways. Without some trickery (reading up on partitioned sieves and stuff), looks like I'm actually approaching the limit of how many primes I can generate gg. Original problem was actually just to check if a list of arbitrary large numbers were prime, so turns out using BigInteger.probablePrime() ending up being a way faster solution (well not really arbitrary and there's probably some really fancy mathematical way to do it, but math). Now just to code my own version of Miller Rabin, hue. I made a sieve with some optimizations, source at https://github.com/Misirlou/CparParallelSieve/blob/master/single.c There are 3 different functions, named 1,2 and 3 . The first function is terribly slow for anything greater than n=2^27, that is computing all primes lower than 2^27. I can get the other ones to run till 2^33 under a minute. The 3rd function takes an extra argument that defines a block size. This is used to split the sieve into little pieces so the array gets stored in cache instead of RAM, which is a much faster memory, as the results I collected can prove, on google spreadsheet I also stored the primes not as an int array but in a char array. Every bit of a char represents a number, so one char can hold 8 "numbers". If it's unmarked when the computation is finished, it means that number is a prime. I also don't have a position for even numbers, I skip them entirely because the only even number that is prime is 2. All of this was done in an effort to use the least amount of memory. The code gets a little more tricky and it takes more operations to access an element but these operations are meaningless compared to what I save in memory access. On your code shouldn't marked and sieve be the same array? | ||
aksfjh
United States4853 Posts
http://www.github.com/aksfjh/heartbleed | ||
| ||