|
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 September 18 2011 01:21 Shootist wrote: Out of curiosity, what domain are most of the programmers/developers here in? Web, mobile, enterprise systems, etc?
I run a little web agency where I also do the web development work (HTML5/PHP/MySQL).
My field is telecommunications, fancy word for network programming. I work as an IT consultant though so it pretty much depends on the project I'm working on, but right now it's with Ericsson which is great because that's my speciality.
(oh and I hate web development )
|
On September 22 2011 05:19 Bigpet wrote: Also hurray for the formal signing of C++11 as an ISO standard. I'm hereby vowing that I will never again use memcpy() on any project where I'm allowed to use C++11. RValue references (move constructors specifically) and the new Array class (well not so new, it's been in TR1) will make memcpy finally obsolete for me. With the possible exception of having to use shitty APIs that make me do it.
C++11 has some cool features I've been missing for ages:
* non-const copying/moving from temporary objects - this removes the need for const correctness entirely for classes for which you do not want const behavior; this wasn't the case till now since temporary objects were implicitly convertible only to const references, which caused an avalanche effect in the entire class, requiring const correctness everywhere * variadic templates, macros, typesafe functions - I don't need to explain how useful they are * perfect forwarding of parameters - my pointer wrapper wouldn't be possible without it * final classes and methods - I haven't been able to get them working quite yet * initializer lists - for any custom array class, though variadic constructors work just as well * constructor calling another constructor - would be better with "this" and "super" keywords, but the latter is not exactly possible due to multiple inheritance * auto and decltype - decltype/typeof should have been in the first standard, they are infinitely useful; in fact, for a long time I tought typeof is in standard c++ * strongly typed nullptr, enums - typesafe null was already possible, typesafe enums not quite so due to too much overhead, still no typesafe boolean * template typedefs - long overdue * threads - ditto; I have yet to play with them though * reference wrappers - they are useful but I have better  * function wrappers - ditto 
Features that are quite frankly useless or outright dangerous:
* explicit conversion operators - just use toWhatever() methods and let's forget about silly casts * user defined literals - just encourages unreadable cluttered code, it will be abused much more than operator overloading * compatibility with C/C++ - it would be time to drop any backwards compatibility, they cause insane complications * lambda functions - opinions vary, I think they just make the code unreadable * generalized constant expressions - and yet still no functions that can be calculated in compile-time and used in constant expressions * foreach loop - it is already possible with macros with even nicer syntax, no type information needed * alternate function syntax - I didn't like it in the SPECS grammar either, and I don't like them here either; people just got used to the C-like function signature syntax, and this new style do not have any visible advantage, other than easier compiler and grammar design * unrestricted unions - unions were pretty useless (and quite dangerous) to begin with, they should be dropped altogether * various unicode encodings and string literals - I do not understand why can't everything be in either UTF-8 *or* UTF-32; UTF-8 has already proven itself, or if it causes problems, UTF-32 * the "delete" keyword applied to constructors or functions is a mistake; it violates the contract of the class, it should throw some kind of UnsupportedOperationException instead of compile error * hash tables - almost everyone already has some kind of hash table implementation; standardizing it is cool, but making a standard hash function that may or may not fulfill a defined quality (universal hashing, perfect hashing) is pointless; also, linear chaining sucks, hash table with universal hash function + set instead of chaining is best * regular expressions - worse than in Java * smart pointers - KILL IT WITH FIRE, they fail even in the case of a doubly linked list, they simply can NOT replace garbage collection * random number generators - IMHO random number generators shouldn't be in the core part of the language
Features still missing from it and other unsolved problems
* PROPER EXCEPTION HANDLING AND TYPE SYSTEM ARRRRRGGGHHH; they even removed exception specifications the fools * the type system is still flawed, instead of hacking it with rvalue references and such, they should redesign it; it makes no sense to have pass by value, pointer, reference, rvalue reference, and const versions of these, when you can get by 2 of these, or 3 if you really want to have both heap and stack allocation * also, clear distinction between polymorphic and value types; I had weeks of headaches trying to prevent object slicing arising from passing a subclass by value; walks hand in hand with assignment operators unfortunately * garbage collection, man! it is really, really useful; everything could be heap allocated if moving is allowed and a generational/incremental collector is used, but can be used even if both heap and stack allocation is kept * packages/modules are LONG, LONG OVERDUE, #include is absurd * no definite sizes for primitives, altough I have some template metaprogramming tricks that only accepts integers of a given size and signedness, or causes a compilation failure, so while it is not an immediate concern, it should be addressed properly nonetheless; primitives really should be called int32, int64, uint32, etc * a resultof keyword to determine the return type of a function with a given signature, with SFINAE propagation if the function does not exist * still no goddamn typesafe booleans * order of evaluation is still not defined * too much "undefined behavior", a worthy standard should have exactly ZERO of these * default constructor, copy constructor or assignment operator SHOULD NOT be generated unless asked for; there should be a Copyable or some other keyword to enable it * get rid of multiple inheritance * static_assert is nice, but concepts would be nicer * precedence amongst implicit conversion operators, this came up surprising often * multimethods that select the appropriate function to called based on the dynamic type of the parameter; arises naturally in game logic design where you have a nice Actor base class and you need different interactions between actors based on what exactly are they
|
On September 22 2011 06:21 SpoR wrote: Your last name is spor, sick
yerr, you could say i'm a funguy   lol I sorted out my issue regarding the code I posted yesterday. I added an extra step that I didnt need. Apparently you dont use edited fields for displaying alphabetic data. I shouldve seen that earlier!
|
On September 22 2011 05:19 Bigpet wrote:Show nested quote +On September 22 2011 05:03 doktorLucifer wrote: /*is the &* correct? I know that the formal parameters are usually dereferenced, and scanf usually needs an address operator. But since I'm passing an address in the first place, can I just use 'scanf("%d %d", x, y)' ? */ Yes &* is redundant unless the * operator is overloaded which it isn't here . (edit: looks like C code, so ignore the last part) edit: OMG. Don't do the while(1);. Just use getchar() to halt the console until you press a button. Also hurray for the formal signing of C++11 as an ISO standard. I'm hereby vowing that I will never again use memcpy() on any project where I'm allowed to use C++11. RValue references (move constructors specifically) and the new Array class (well not so new, it's been in TR1) will make memcpy finally obsolete for me. With the possible exception of having to use shitty APIs that make me do it.
I'm using while(1); since when I use getchar();, it sometimes fails to work, esp if there was a scanf(); earlier, i don't know why ;_;
|
Hey guys I'm taking a CS 2 course right now that focuses on graphical stuff written in java. In this assignment I am supposed to create an ArrayList<Disk> instance variable to hold the collection of disks, also with an instance variable 'current' of type int that holds the index of the current disk. And pretty much I have a bunch of methods to draw the disk, add, remove, change color, etc.. But I am supposed to be able to move the up, down, left, and right arrow keys to change to whatever disk. Here's a snip of the code I'm having trouble with. The left and right arrow keys work when I want to change to a disk on the left or right. But I'm not sure how to do the Up and Down keys using this type of syntax? I know there's an easier way to do this doing something like (0,1) to move up, (1,0) to move left. Any help would be appreciated. Thx guys.
public void keyPressed( KeyEvent e ) { int code = e.getKeyCode();
if( code == KeyEvent.VK_LEFT ) { disks.get(current--); } else if( code == KeyEvent.VK_RIGHT ) { disks.get(current++); } else if( code == KeyEvent.VK_UP ) { } else if( code == KeyEvent.VK_DOWN) { }
|
Hey everybody I'm in a course teaching C++ to people who initially learned java and I'm having a ton of trouble with a couple particular errors.
The code and compiler output is located here.
In particular, the errors about array declaration (lines 32, 179, 234) are killing me right now, though any help at all would be appreciated.
Thanks a bunch.
|
C++ arrays are quite unlike Java arrays, the best way to use them is to avoid them like plague, they are the single worst part of C++.
Dynamic length array parameters automatically decay into pointers, so if you have an f(double v[]) method, that is equivalent to an f(double*) method. Similarly, double[] as return type is equivalent to double*. Pointers to objects and arrays are not exactly distinguishable, and you especially can't get the length of an array from its pointer.
In essence, you are using {this, style, of initialization}, aka initializer list for pointers, at lines 32, 179, 188, 203, 234. I doubt it is legal. You are also mixing dynamic length arrays and static length arrays, nothing good can come of that.
My advice: * Try using only static length arrays; double a[5] instead of double a[], double values[5] instead of double values[]. Perhaps it will work, perhaps not, my knowledge is a bit sketchy about static length arrays. Edit: NEVER MIND. I've tested a few cases, you can initialize and even assign static length arrays the way you want, BUT as member variables they automatically decay to pointers. * If you use C++11, formerly known as C++0x, use std::initializer_list instead of arrays as parameter to the constructor. * Like me, implement your own Array class that does not have any of the drawbacks of arrays, with an std::initializer_list constructor and assignment operator. Then the construction from initializer list you are trying will definitely work.
I recommend registering at Stack Overflow and asking your question there.
Edit: Looks like it is not possible to use an array as a default parameter: http://stackoverflow.com/questions/4894094/passing-an-array-as-a-parameter-with-default-values-into-int-main/4894140#4894140
Edit: Best I could come up with:
#include <Frigo/Lang/all> #include <Frigo/Lang/all.cpp>
using namespace Frigo::Lang; using namespace std;
class Test {
public:
/* * No parameter is given, we use {1, 2, 3, 4, 5} */
Test () : n (5), v (new int32[5]) { for( int32 i = 0; i < n; i++ ){ v[i] = i + 1; } }
/* * Initialize from static length array; static length array is passed by reference, ugly syntax */
template <int32 m> Test (int32 (&p) [m]) : n (m), v (new int32[m]) { for( int32 i = 0; i < n; i++ ){ v[i] = p[i]; } }
/* * Initialize from brace-enclosed initializer list, C++11 only */
Test (std::initializer_list<int32> list) : n (static_cast<int32>(list.size())), v (new int32[list.size()]) { int32 i = 0; for( auto iter = list.begin(); iter != list.end(); ++iter ){ v[i] = *iter; i++; } }
~Test () { delete [] v; }
protected:
int32 n; int32* v;
private:
Test (Test&); Test& operator = (Test&);
};
template <class T, int32 n> int32 lengthof (const T (&) [n]) { return n; }
int32 main (int32, char*[]) { int32 v[] = {1, 2, 3}; // this is actually int32 v[3], not int32* Test x; Test y(v); Test z{1, 2, 3, 4}; // Test z = {1, 2, 3, 4}; // DOES seem to involve copy constructor, contrary to established practice in other constructors where = is just syntactic sugar }
|
-module(chatbot). -export([matches/2,matches/3,words/2]).
matches(H,{match,M}) -> matches(H,M,[]). matches(_,[],Acc) -> Acc; matches(H,[{I,L}|T],Acc) -> matches(H,T,[lists:sublist(H,I,L)|Acc]).
words(String, Regexp) -> matches(String,re:matches(String, Regexp)).
Words_1 = "[^ ]+". Words_2 = "[A-Za-z'-]+".
this doesnt compile and i dont know why D: im trying to turn each word in a string into a list. but Words_1 = "[^ ]+". Words_2 = "[A-Za-z'-]+". doesnt compile, some sort of syntax error =/ can i ask anybody for help?
|
Hey,
I've recently started programming XNA games. Followed a amount of tutorials and have some contacts that help me with small problems.
However, anyone can recommend me a book regarding XNA? I read some stuff on the web there are no decent books and you just have 'to do it'. I'm not really a fan of non-stop following tutorials. I like to read the proces and everything related to XNA by learning from a book.
Any help?
|
|
On September 17 2011 13:44 eFonSG wrote:Show nested quote +On September 17 2011 12:52 tofucake wrote:On September 17 2011 12:30 eFonSG wrote: Hey i was wondering if anyone with a decent amount of knowledge in Java could help me with some code? Im pretty confused right now, and ive been staring at my screen for a few hours hoping i would miraculously figure it out. I really only need some help getting started in the right direction, because im just lost from the start. Elaborate? I know the OP says not to post and ask what's wrong, but you can post and say "I tried X, Y, and Z and I still don't know what's going on. Can anyone help?" That's actually the attitude I'd love to see going on. On September 14 2011 08:14 Clank wrote:On September 13 2011 13:26 catamorphist wrote:On September 13 2011 10:59 Clank wrote: ok, im in high school and looking for some good extracurriculars for colleges. I have limited knowledge in programming, as I've only taken 2 classes, one intro to basic at school, and then an intro to python. I did very well in those classes and enjoyed them , but still, im quite nooby. Basically what im wondering is, do you think it would be possible for me to try and learn how to make a very basic app for the app store? And if that would be too challenging, do you have any suggestions to try and incorporate programming into a fun, good extracurricular? No, you could do it in a couple weeks worth of evenings. Go do it! ok, thank you! any tips for getting starting? Just Do It™. That's my approach. Can do, Im trying to make a program that will ask for a user input for a full name, then re-arrange the order and capitalization to match the exercise ( and it forces me to use nextLine() rather than next()). For example import java.util.Scanner; public class ThreeNames{ public static void main(String[]args){ Scanner A = new Scanner (System.in); System.out.print("Please enter your name: "); String Name = A.nextLine(); The user would type in a full name, such as firstname middlename lastname, i need to then rearrange it so that it shows the initials(F.M.L), and then re-arrange it so that its Lastname, firstname M. Ive been trying to use substring() to break apart the the string Name into just the first letters so that i can capitalize them String B = (Name.substring(0,1)).toUpperCase()); This would give me the very fist letter of the first name so that i could capitalize it. My problem is that i dont know how to get the first letters of the middlename and lastname, so i can capitalize them and put them in proper format. I was under the assumption that substring() can only have ints as its argument and not whitespace characters, which was my first guess. But that failed pretty miserably. So im not really sure how to break up the string Name because i cant predict how long the name will be, and therefore cannot have an actual int value for the substring. Maybe im looking at it wrong, but any help would be greatly appreciated.
You can read the Whole string in and then split it on the space character to get 3 separate strings back, if you can assume that the user will input in the correct order then its pretty simple.
ex.
String fullName = key.readLine(); // key is a BufferedReader String [] nameList = fullName.split(" ");// space might need escaped, cant remember String firstName = nameList[0]; String middle = nameList[1]; String last = nameList[2];
char firstInitial = firstName.charAt(0); // so on so forth.
|
Hey guys I am rank 44 bronze league at Java, I've never posted here in the Java strategy forums and I was hoping someone could help me out. Basically this is the last method of my assignment that I need to write, and I'm having trouble and preferably it needs to be done in 2 hours. Any help would be appreciated.
/** * Find the position in the observation array of the first value * greater than or equal to the argument, if such an element exists * For example, the first day of good rain would be one with rainfall >= 5mm * @param large a double for the search condition value * @return position of element satisfying search criteria * or -1 if no value meets this condition */ public int findPosGreaterthan(double large) {
I think the /** text pretty much explains everything that needs doing but if not I will give a brief explanation. Basically the class is a rainfall (/any weather stat) recording class and the method is to find the first position within the array of values that a certain notable value occurs, determined by the user.
I'm thinking that a while loop is required however I have never written a while loop and whilst I understand the concept, I have no idea of how to structure it, what variables required etc.
Anyways, any help within the next two hours would be greatly appreciated and any input within the next 14 hours (which is when it is officially due) would also be appreciated, however I will be quite drunk by that stage...
Cheers
|
On September 22 2011 07:43 Frigo wrote: Features that are quite frankly useless or outright dangerous:
... * lambda functions - opinions vary, I think they just make the code unreadable Personally, I think there are enough cases where they are really helpful that they are a very welcome addition.
* foreach loop - it is already possible with macros with even nicer syntax, no type information needed Nothing with macros is nicer syntax. :-)
Macros are a necessary evil and I wouldn't want them to go, but I do think that looking at how macros are used and adding first-class language support is a very worthwhile task. Macros have too many problems.
* the "delete" keyword applied to constructors or functions is a mistake; it violates the contract of the class, it should throw some kind of UnsupportedOperationException instead of compile error Whoa, what?
If you have a function that always throws something like UnsupportedOperationException, that is a strong indication that your design is broken. Why would you have a runtime error when you could have a compile time one? What possible use could that have? Essentially the delete keyword in these ways is saying those function's aren't part of the class.
(There are some cases where an UnsupportedOperation is in some sense the least-broken approach, but it's still broken. If an operation is unsupported... it shouldn't be there!)
* smart pointers - KILL IT WITH FIRE, they fail even in the case of a doubly linked list, they simply can NOT replace garbage collection While I am much less of a C++ fan than I was a while ago and think that basically everything should be written in a managed language nowadays and so agree with the second part, if you're forced into using C++, smart pointers make it way more bearable. Yes, you have to know what they can and can't do, but that's true of everything. C++ isn't exactly a hold-your-hand language.
Features still missing from it and other unsolved problems
* PROPER EXCEPTION HANDLING AND TYPE SYSTEM ARRRRRGGGHHH; they even removed exception specifications the fools Exception specifications were removed because the original design was broken and idiotic (exactly because it wasn't part of the type system).
I'm not sure what I'd like to see here. On one hand, one of the most obnoxious things about Java to me in a lot of cases is its checked exceptions; but at the same time, it would be nice to have it check them on demand.
* order of evaluation is still not defined * too much "undefined behavior", a worthy standard should have exactly ZERO of these I go back and forth on this. On one hand, I see where you're coming from, but on the other... compiler writers really can (and do) take advantage of that undefined behavior.
|
Hey guys Im working on a program in c++ to output the weekly salary of employees but for some reason when I input the hours, it is giving me these ridiculous answers. Possibly the problem lies in the declaration of variables? im not sure.
+ Show Spoiler + #include <iostream> using namespace std;
int main () { double hours; double overtime; double salary; salary = (8 * hours); cout << "Input the amount of hours worked: " <<endl; cin >> hours; if(hours<=40) cout << "Your weekly salary is " << salary << " dollars" <<endl; else if(hours>40) cout << "Your weekly salaray is " << overtime << " dollars" << endl; return 0; }
|
Anyone have any good resources on game networking?
I'm trying to make a multiplayer (hopefuly p2p via wifi) for the iphone.
|
Show nested quote +* order of evaluation is still not defined * too much "undefined behavior", a worthy standard should have exactly ZERO of these I go back and forth on this. On one hand, I see where you're coming from, but on the other... compiler writers really can (and do) take advantage of that undefined behavior.
Precisely. Undefined behavior, while annoying in terms of interpreting the semantics of a language, can be critical for compiler optimizations. A handful of examples are in this LLVM blog post:
http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html
Another example are C++ STL iterators that provide very precise rules for when an iterator is invalidated, but makes the behavior undefined when those rules are broken. That way, library writers don't have to hamstring performance in the name of catching these points when behavior goes undefined.
|
On September 25 2011 08:13 Frosticles wrote:Hey guys Im working on a program in c++ to output the weekly salary of employees but for some reason when I input the hours, it is giving me these ridiculous answers. Possibly the problem lies in the declaration of variables? im not sure. + Show Spoiler + #include <iostream> using namespace std;
int main () { double hours; double overtime; double salary; salary = (8 * hours); cout << "Input the amount of hours worked: " <<endl; cin >> hours; if(hours<=40) cout << "Your weekly salary is " << salary << " dollars" <<endl; else if(hours>40) cout << "Your weekly salaray is " << overtime << " dollars" << endl; return 0; }
You can't declare salary like that. You do 'salary = 8 * hours', but hours does not have a value yet at that point so salary will have weird values. Only after you get your hours input you can calculate the salary.
|
On September 25 2011 08:39 Glowbox wrote:Show nested quote +On September 25 2011 08:13 Frosticles wrote:Hey guys Im working on a program in c++ to output the weekly salary of employees but for some reason when I input the hours, it is giving me these ridiculous answers. Possibly the problem lies in the declaration of variables? im not sure. + Show Spoiler + #include <iostream> using namespace std;
int main () { double hours; double overtime; double salary; salary = (8 * hours); cout << "Input the amount of hours worked: " <<endl; cin >> hours; if(hours<=40) cout << "Your weekly salary is " << salary << " dollars" <<endl; else if(hours>40) cout << "Your weekly salaray is " << overtime << " dollars" << endl; return 0; }
You can't declare salary like that. You do 'salary = 8 * hours', but hours does not have a value yet at that point so salary will have weird values. Only after you get your hours input you can calculate the salary. To be even more accurate, you declare some double which are stored on the stack, but don't initialize them. So you end up with whatever was on the stack at that place at runtime as value for salary/hours/... Last but not the least, you compute the value of salary before receiving the value of hours. C(++) doesn't do symbolic calculi. When performing assignment (=), it just evaluates the right operand and assign the result to the left one. To explain that in another way, if salary(h) is the function giving the salary for given hours, you cannot calculate salary before knowing the value of h. Same goes for any computation in C, pay attention to the order of your different "=" operators.
|
On September 23 2011 18:48 tISL wrote: Hey,
I've recently started programming XNA games. Followed a amount of tutorials and have some contacts that help me with small problems.
However, anyone can recommend me a book regarding XNA? I read some stuff on the web there are no decent books and you just have 'to do it'. I'm not really a fan of non-stop following tutorials. I like to read the proces and everything related to XNA by learning from a book.
Any help?
I can personally recommend "Microsfot XNA Game Studio 3.0 Unleashed" ( http://www.amazon.co.uk/Microsoft-XNA-Game-Studio-Unleashed/dp/0672330229/ref=sr_1_1?ie=UTF8&qid=1316909078&sr=8-1 ). It basically covers the entire framework from beginning to end.
|
Just as a reminder, you shouldn't post in this thread asking for direct answers to your homework. You won't learn well that way. Ask specific questions about things that genuinely confuse you after thinking about them.
I'll start us off (although it's not "homework"). I've read and understand http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf subsection 10.4.3 Entering Function Code, item (1), but I don't understand what purpose this serves the language in the bigger picture. For example, if I create an anonymous function and don't explicitly bind a context, the thisArg comes out as undefined -- which a lot of programmers I think assume "inherits" from lexical scope much like any variable (the nearest scope entry that is non-undefined wins). Any ideas on why this is the way it is? Does this make the language cleaner, so that there are fewer mistakes due to context-ambiguity? Are there any positive benefits of this (gives the programmer a tool, rather than just constraining sloppy code)?
+ Show Spoiler +I think it is security-related.
|
|
|
|