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.
On June 30 2015 02:13 bangsholt wrote: Meh - software engineering and computer science has this thing, where if you only work for the 40 hours you're supposed to and request actual overtime payment for your overtime. You're not a real programmer.
I'm very content with not being a real programmer
Eh, while it may also be a bit programmer culture thing, it's mostly a corporate thing. There are programmers in the office who get paid overtime. But the more senior employees get paid by performance. My contract states that I don't get paid overtime. I can get certain bonuses though. In practice, it means that I work whatever hours I have to to get the task done. I would probably get the bonus even if I didn't do that. Most of the people I knew at uni working in big companies have a similar setup. And I have worked in a small company too. There, we were 4 CS specialists (all MSc, so pretty highly educated), and worked til the work was done. It's a lot of fun to be part of something like that, but afterwards you look at the hours worked and the salary earned and realize that it didn't pay off at all.
But I think most companies end up being like that (not that I have much experience outside of CS): you either have a boring monotonous job where you work your 8 hours a day and strictly log overtime. Or you have a job that you can put some creativity and allows you to grow as a person, but anything extra you put in does not earn you more money.
been working on adding a sweet feature (allthough essentially just a shorthand) to my variant implementation (named abstract, unsafe for anything except my personal use): transparent function call operators.
ie. if every type abstracted ({ type0, ..., typeN-1 } from abstract<type0, ..., typeN-1> provides a correctly qualified function call operator (qualified part is not 100%) for a given set of arguments ({arg_type0, ..., arg_typeM-1}), and the set of return types ({ return_type0, ..., return_typeN-1 }) has a common type, a function call operator is automatically exposed in the interface that looks ~like:
which does the dispatch to the concrete function call operators.
example: set of abstracted types is {cat_t, dog_t, worm_t} set of (qualified) argument types is {std::ostream&} set of return types is {void, void, void} with common type = void operator exposed in abstract<cat_t,dog_t,worm_t>'s interface is void operator()(std::ostream&);
Your code formatting is killing me nunez... [type]<break><indent>[name][args] is freaking hard to follow.
And now, for some fun with PHP (I know you all hate it). Recently I was playing around with the most common and at the same time most obnoxious PHP data structure - an array. Since in PHP any variable can hold any value at any point in time you have to be extra careful with them. Imagine such a simple thing:
$arr = getSomeArray($someArgs);
$something = $arr[0]; $something = $arr[1];
All cool and dandy. Unless something went wrong down the line and instead of an array we get some other value or an array that's shorter than expected - we'll end up fatalling all the time. So we end up putting guards like that:
$arr = getSomeArray($someArgs);
if (is_array($arr)) { if (isset($arr[0])) { $something = $arr[0]; }
if (isset($arr[1])) { $something = $arr[1]; } }
Tedious. But it can be solved with array shifting, which will give us what we want or null if our array is empty or is not an array at all. We can check that later.
Now, the funny thing is, that usually by looking at a code like that you'd expect the first stuff posted ($arr[0], $arr[1]) to change the value of $something. While the last example should in theory assign the same value to $something in both cases. Not so much. By default function arguments in PHP are passed by value, in case of array_shift they're passed by reference so by using array_shift we also change the $arr. While it might not be such a scary thing and if you know how it all works you immediately know that, but it can get very ugly very quickly since you can end up with some nasty code that's hard to read. Imagine this:
$something = array_shift($arr);
/* Block of code */
if (something or other) { /* Some more code */
$something2 = array_shift($arr); }
You see that and now you're thinking. OK, I know exactly what's happening here, but did the person who write it also know this? Did that person remember that the array was shifted before shifting it again?
Run into a bug just like that yestedray, when someone forgot about shifting the array beforehand and tried to shift it again. It's freaking annoying when if you want to do multiple shifts you have to add extra comments just to make your intentions clear:
/* First shift -> get controller object */ $controller = array_shift($requestData);
// somewhere down the line
/* Second shift -> get action name */ $action = array_shift($requestData);
Thank you for reinforcing my hatred of php. I was on the verge of forgetting how much of a cesspool the language is. I particularly like this page, which aims to show some terrible things of php, but inadvertently ends up showing off some of the horrors of perl as well: http://tnx.nl/php.html
I particularly like how he thinks the following is a good idea:
On July 01 2015 11:35 Acrofales wrote: Thank you for reinforcing my hatred of php. I was on the verge of forgetting how much of a cesspool the language is. I particularly like this page, which aims to show some terrible things of php, but inadvertently ends up showing off some of the horrors of perl as well: http://tnx.nl/php.html
I particularly like how he thinks the following is a good idea:
lc $str cmp lc $str2
Yeah, but I don't really think you should be using a 10-year old stuff to show this things. PHP has evolved pretty much since (but is still terrible). PHP 7 will solve a lot of issues though (like type hinting for ints, strings and such, thank the gods). Still a far way to go and I don't have much faith in Zend with their attitude of "PHP is not designed with programmers in mind" (if this one thing would change the PHP could actually become good as it would require cleaning up the mess, even at the cost of breaking backwards compatibility entirely).
@manitou my formatting doesn't jive well with constructors and conversion operators cuz they don't really have a name! constructors are a bit special though with the member initializer list, but i got no excuse for the sweet, sweet, conversion operators.
i love my c++ typesystem, hard to imagine writing in a language without something similar. even harder if you can't trust your fellow programmers to be aware of the functionality of the functions they use! nice read.
/* First shift -> get controller object */ $controller = array_shift($requestData);
// somewhere down the line
/* Second shift -> get action name */ $action = array_shift($requestData);
If inline comments are required, the function is often too long anyway. Regardless, in this case I'd use array destructuring. Something like this:
list($controller, $action) = $requestData;
On July 01 2015 11:35 Acrofales wrote: Thank you for reinforcing my hatred of php. I was on the verge of forgetting how much of a cesspool the language is. I particularly like this page, which aims to show some terrible things of php, but inadvertently ends up showing off some of the horrors of perl as well: http://tnx.nl/php.html
PHP certainly has more than its fair share of warts and worse. I wouldn't even argue with people calling it a terrible language altogether.
Having mutable data structures and functions to manipulate them does not seem like the most pressing problem however, and it's one that exists in many languages. The purpose of the array_shift function is to return the first value in the array and remove it from the array.
It's usually easy enough to avoid mutating data in PHP, though of course it can't be enforced with arrays.
That page is pretty old and doesn't really cover the main problems of modern PHP that well, though native function count / naming / other inconsistencies is still one of the biggest flaws. Even the infamous article PHP: a fractal of bad design (Manit0u posted a link above) is more accurate.
And PHP standard library could certainly use additional data structures, including immutable ones.
On June 28 2015 03:17 phar wrote: Sorry, I mean this (my terminology is probably off):
Fast:
ArrayList<Bar> foo;
for (Bar b : foo) { something(b); }
Fast (this is probably what you would also call random access, my fault for using wrong word sorry):
ArrayList<Bar> foo;
Bar b = foo.get(index);
Slow:
ArrayList<Bar> foo; Bar b;
if (foo.contains(b)) { something(b); }
This may be easier if you just post your code, I think we're having a hard time understanding exactly what your issue is because we're just guessing as to what it is you're doing exactly. In particular that high of memory usage seems wrong if your algorithm is supposed to be linaer space (it is linear space, yea? you're not using one of those crazy node^2.4 time / node^2 space complexity algorithms, right?)
20 microseconds for a single access into a HashSet or ImmutableSet still sounds kinda high. Though, for example, if you're using ImmutableSet and on an old version, there are some hilariously degenerate cases where a contains could take ~ms.
final List<ArrayList<Integer>> smallerEdges = new ArrayList<ArrayList<Integer>>(graph.numVertices); final List<HashSet<Integer>> biggerEdges = new ArrayList<HashSet<Integer>>(graph.numVertices);
for (int i = initialPosition; i < smallerEdges.size(); i += step) { for (Integer smallVertex : smallerEdges.get(i)) { for (Integer bigVertex : biggerEdges.get(i)) { if (biggerEdges.get(smallVertex).contains(bigVertex)) { triangles.add(new Triangle(smallVertex, i, bigVertex)); } } } }
The algorithm efficiency isn't the problem, the problem is that I'm under-utilizing the cache, so I probably need another algorithm so my accesses are more localized...
On June 28 2015 03:17 phar wrote: Sorry, I mean this (my terminology is probably off):
Fast:
ArrayList<Bar> foo;
for (Bar b : foo) { something(b); }
Fast (this is probably what you would also call random access, my fault for using wrong word sorry):
ArrayList<Bar> foo;
Bar b = foo.get(index);
Slow:
ArrayList<Bar> foo; Bar b;
if (foo.contains(b)) { something(b); }
This may be easier if you just post your code, I think we're having a hard time understanding exactly what your issue is because we're just guessing as to what it is you're doing exactly. In particular that high of memory usage seems wrong if your algorithm is supposed to be linaer space (it is linear space, yea? you're not using one of those crazy node^2.4 time / node^2 space complexity algorithms, right?)
20 microseconds for a single access into a HashSet or ImmutableSet still sounds kinda high. Though, for example, if you're using ImmutableSet and on an old version, there are some hilariously degenerate cases where a contains could take ~ms.
final List<ArrayList<Integer>> smallerEdges = new ArrayList<ArrayList<Integer>>(graph.numVertices); final List<HashSet<Integer>> biggerEdges = new ArrayList<HashSet<Integer>>(graph.numVertices);
for (int i = initialPosition; i < smallerEdges.size(); i += step) { for (Integer smallVertex : smallerEdges.get(i)) { for (Integer bigVertex : biggerEdges.get(i)) { if (biggerEdges.get(smallVertex).contains(bigVertex)) { triangles.add(new Triangle(smallVertex, i, bigVertex)); } } } }
The algorithm efficiency isn't the problem, the problem is that I'm under-utilizing the cache, so I probably need another algorithm so my accesses are more localized...
Implementing dumb RFID readers and client demanding the system to basically read the user's mind so I'm wasting a ton of time navigating the JavaScript maze of a dozen modal windows and twice that number of ajax calls. Working 10 days a week is not fun
On July 02 2015 18:13 Blisse wrote: Not really. Foreach loops are backed by Iterators anyways.
The language is Java if that helps.
What does your profiler say about what's taking up all the time?
the nested for loops costs about as much as the contains operations
turns out it was probably the algorithm efficiency, nested for loops are bad. we figured out a more effective solution, i'll share after the deadline passes if y'all are interested because it's actually pretty neat
On July 02 2015 18:13 Blisse wrote: Not really. Foreach loops are backed by Iterators anyways.
The language is Java if that helps.
What does your profiler say about what's taking up all the time?
the nested for loops costs about as much as the contains operations
turns out it was probably the algorithm efficiency, nested for loops are bad. we figured out a more effective solution, i'll share after the deadline passes if y'all are interested because it's actually pretty neat
i recently finished my first course in c++. having had a few years of programming coursework in high school (basic java and python stuff) so i started with the data structures and algorithms course. it was a good way to start learning the language, but i'm having some problems trying to explore on my own
first of all now that i'm back on my os x laptop i'm sort of corralled into using xcode. for the course i just stuck to beloved vim and i've never really had to use a full ide so maybe that's part of my confusion. a bigger deal is that os x compatibility seems to be an issue for some things
also i don't really get how to learn to download and learn to use libraries and APIs, seeing as my course just involved basic command line tools with the standard library. well say i want to learn a bit about opengl now. luckily the framework is in xcode, so i don't have to download anything. but os x just got 4.1 compatibility with mavericks, and all the tutorials i can find online either assume building on knowledge of older versions or are filled with lots of confuso computo lingo that i am unfortunately not yet familiar with. on the other hand java made it much easier to learn graphics as it had some graphics functionality in the standard API
so i guess my questions are 1) is xcode a bad idea? 2) can you recommend some introductory material for learning simple graphics or user interface or game programming or the like with libraries that would work on mac?
ALSO quick one, good IDE for python or java should I decide to take it easy?
thanks in advance, hope i described my confusion clearly
On July 05 2015 00:04 catplanetcatplanet wrote: first of all now that i'm back on my os x laptop i'm sort of corralled into using xcode. for the course i just stuck to beloved vim and i've never really had to use a full ide so maybe that's part of my confusion. a bigger deal is that os x compatibility seems to be an issue for some things
I've never heard of anyone who really liked xcode. Macs were standard issue at work last summer and everyone used emacs or vim, you can use command line g++ to build simple things and make to build complicated things, if you try hard enough it's still a Unix system at heart with all the good tools :D
On July 05 2015 00:04 catplanetcatplanet wrote: also i don't really get how to learn to download and learn to use libraries and APIs, seeing as my course just involved basic command line tools with the standard library. well say i want to learn a bit about opengl now. luckily the framework is in xcode, so i don't have to download anything. but os x just got 4.1 compatibility with mavericks, and all the tutorials i can find online either assume building on knowledge of older versions or are filled with lots of confuso computo lingo that i am unfortunately not yet familiar with. on the other hand java made it much easier to learn graphics as it had some graphics functionality in the standard API
http://learnopengl.com/ is a modern OpenGL resource which is nice, and geared towards beginners, I haven't checked it out in a few months but I think I remember pretty good intro lessons where they describe the process of setting up your build environment.
edit: those tutorials use Visual Studio which may not be great for you, but they also describe using CMake to set up your VS projects so you should be able to pretty easily generate a make project instead.
On July 05 2015 00:04 catplanetcatplanet wrote: ALSO quick one, good IDE for python or java should I decide to take it easy?
thanks in advance, hope i described my confusion clearly
On July 05 2015 00:04 catplanetcatplanet wrote: first of all now that i'm back on my os x laptop i'm sort of corralled into using xcode. for the course i just stuck to beloved vim and i've never really had to use a full ide so maybe that's part of my confusion. a bigger deal is that os x compatibility seems to be an issue for some things
I've never heard of anyone who really liked xcode. Macs were standard issue at work last summer and everyone used emacs or vim, you can use command line g++ to build simple things and make to build complicated things, if you try hard enough it's still a Unix system at heart with all the good tools :D
On July 05 2015 00:04 catplanetcatplanet wrote: also i don't really get how to learn to download and learn to use libraries and APIs, seeing as my course just involved basic command line tools with the standard library. well say i want to learn a bit about opengl now. luckily the framework is in xcode, so i don't have to download anything. but os x just got 4.1 compatibility with mavericks, and all the tutorials i can find online either assume building on knowledge of older versions or are filled with lots of confuso computo lingo that i am unfortunately not yet familiar with. on the other hand java made it much easier to learn graphics as it had some graphics functionality in the standard API
http://learnopengl.com/ is a modern OpenGL resource which is nice, and geared towards beginners, I haven't checked it out in a few months but I think I remember pretty good intro lessons where they describe the process of setting up your build environment.
edit: those tutorials use Visual Studio which may not be great for you, but they also describe using CMake to set up your VS projects so you should be able to pretty easily generate a make project instead.
thanks so much for the answers and the opengl site! i've successfully built the library and am on my way to finally learning some opengl
one more question, since I had to use cmake to generate files for the IDE (specifically xcode) is there a different way of getting this to work with a command line editor? and what exactly is a make project?
e: upon further research it appears that editing in vim and building with the xcodebuild command might be the way to go. i will try this out later