|
Battle Bott posted:http://www.urubatan.info/2008/11/commenting-source-code-is-only-for-the-weak/ There's three big problems in that example. The signature implies that the method writes the contents to a file or is at least ambiguous. Then there's the confusing use of Strings, StringBuilders and StringBuffers. Then it returns the results as a return value and in the passed container, possibly killing performance. That being said, I don't agree with the refactored version. I would write it like this to keep the spirit of the original: code:
|
# ? Jul 25, 2009 00:59 |
|
|
# ? Jun 7, 2024 09:51 |
|
Avenging Dentist posted:If you write a function that is only called once (and you never intend to use it other places), you are an idiot.
|
# ? Jul 25, 2009 01:38 |
|
Mustach posted:int main() Wait, people write nonrecursive main functions? How do you write your event loop?
|
# ? Jul 25, 2009 02:24 |
|
I'm poking around boost for the first time and the first area I'm trying out are the functional libraries. I'm trying to figure out if there is a way to write a function that takes some function pointer or functor and returns an anonymous function that say, does that function twice. The signatures can be fixed, but if you can do it for any function I'd be pretty impressed. I've checked out boost::function, lambda and phoenix and I haven't managed to get anything working that does this exactly (without making the parameter of twice an actual function pointer). I know I could do this by making a class for this specific purpose; I just want to know if it's possible to wrap all this functionality into a single one-line function. My goal is flexibility and minimum LOC. Also no 0x lambdas. So: code:
|
# ? Jul 27, 2009 08:01 |
|
return boost::bind(f, boost::bind(f, _1)); seems to do. http://www.boost.org/doc/libs/1_39_0/libs/bind/bind.html#nested_binds
|
# ? Jul 27, 2009 13:11 |
|
So at my job I've been tasked with making a program that can send a stream of data to another program. This should be really simple but I am almost completely a programming newbie so I didn't really know where to start. A friend suggested using the Asio library in Boost so I am giving that a shot after getting frustrated with conventional Windows sockets. I installed Boost 1.39 and have plugged an example from Boost's tutorials (http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio/tutorial/tutdaytime1/src.html) into Visual Studio 2008. I got past a couple of errors but I can't figure this one out:code:
|
# ? Jul 27, 2009 22:59 |
|
You need to compile the Boost library for it to work (parts of it anyway), the Asio library is not a header only library. It's probably easier to just use the binaries installer http://www.boostpro.com/download. You then need to tell Visual Studio to search in the boost /lib directory for additional linker dependencies.
|
# ? Jul 27, 2009 23:17 |
|
amotea posted:You then need to tell Visual Studio to search in the boost /lib directory for additional linker dependencies. I'm pretty sure the installer does that for you, but then I haven't used it in a long time since I build Boost from source.
|
# ? Jul 27, 2009 23:53 |
|
Avenging Dentist posted:I'm pretty sure the installer does that for you, but then I haven't used it in a long time since I build Boost from source. Shouldn't there be some #pragmas in the boost headers that add the boost lib directories to the right place?
|
# ? Jul 27, 2009 23:59 |
|
floWenoL posted:Shouldn't there be some #pragmas in the boost headers that add the boost lib directories to the right place? No, those pragmas only name the libraries which need to be linked in. This doesn't help with library search. 'HondaCivet' -- if you did build boost you didn't build it for the right flavour. 'mt-gd' denotes a debug build against the multi-threaded debug DLL CRT. See: http://www.boost.org/doc/libs/1_39_0/more/getting_started/windows.html#library-naming
|
# ? Jul 28, 2009 08:58 |
|
ctz posted:No, those pragmas only name the libraries which need to be linked in. This doesn't help with library search. Thanks but could you elaborate on this? It doesn't really provide any direction or instruction or tell me what's going on.
|
# ? Jul 28, 2009 20:37 |
|
Hello, I hope you guys can help me. I'm learning C# as my first programming language (I have a friend who is helping me a bit, thus my choice) and I'm looking for a good book to get to help me learn it from scratch, especially regarding game programming, as I feel I've about reached the bounds of what I can teach myself without direction. If this should be in the .Net thread I'll post it over there but it's not clear to me which thread I should be asking in. Thanks.
|
# ? Jul 29, 2009 05:45 |
|
The Good Professor posted:Hello, I hope you guys can help me. I'm learning C# as my first programming language (I have a friend who is helping me a bit, thus my choice) and I'm looking for a good book to get to help me learn it from scratch, especially regarding game programming, as I feel I've about reached the bounds of what I can teach myself without direction. While it is great that you want to learn, this is the C/C++ thread not a C# thread. You probably want the .net one unless there actually is a C# specific one that I haven't seen.
|
# ? Jul 29, 2009 05:53 |
|
HondaCivet posted:Thanks but could you elaborate on this? It doesn't really provide any direction or instruction or tell me what's going on. Just download the installer from BoostPro Computing and install the first two library types (I think).
|
# ? Jul 29, 2009 05:54 |
|
The Good Professor posted:Hello, I hope you guys can help me. I'm learning C# as my first programming language (I have a friend who is helping me a bit, thus my choice) and I'm looking for a good book to get to help me learn it from scratch, especially regarding game programming, as I feel I've about reached the bounds of what I can teach myself without direction.
|
# ? Jul 29, 2009 14:45 |
Got it working! Yaaay!
Jo fucked around with this message at 22:36 on Jul 31, 2009 |
|
# ? Jul 30, 2009 02:08 |
|
I've seen code by a few people that passes built-in types as const references, e.g.code:
|
# ? Jul 30, 2009 19:17 |
|
Avenging Dentist posted:Just download the installer from BoostPro Computing and install the first two library types (I think). Argh you are right I just didn't install it right. Anyway, so the client and [url = "http://www.boost.org/doc/libs/1_39_0/doc/html/boost_asio/tutorial/tutdaytime2.html]server[/url] parts seem to run without error but I still think they aren't working right. It looks and sounds like the server is supposed to pass a time stamp to the client who prints it up on the screen. When I run it, the server just puts up a blank command prompt screen that just sits there and the client pops one up for a split second and then it disappears. I never see any writing on either but for the client, even if there was any, it'd be pretty hard to read. What am I doing wrong? I haven't changed anything in the code given so it seems funny that I would've broken it already. I am trying to test them on a single machine, is that not possible?
|
# ? Jul 30, 2009 20:11 |
|
DoctorTristan posted:I've seen code by a few people that passes built-in types as const references, e.g. A double is usually 8 bytes, whereas a reference (essentially a pointer under the hood) would be only 4 bytes on a 32 bit machine, so it can reduce the amount of data that needs to be copied around. For int it doesn't really make sense, because it's only 4 bytes, while a pointer or reference is the same size, or even bigger (on a 64 bit machine).
|
# ? Jul 30, 2009 20:12 |
|
HondaCivet posted:When I run it, the server just puts up a blank command prompt screen that just sits there and the client pops one up for a split second and then it disappears. The client is probably exiting once it receives and prints the data. Since it's a command-line thing in Windows it'll close the command prompt almost immediately. The solution is to either 1) run it from Visual Studio (non-debug mode), since Visual Studio will insert a pause before it closes the prompt, 2) run it from Visual Studio in debug mode and set a breakpoint just before you return from main, or 3) open up a command prompt manually and execute the client program from there. Note that in cases 1 and 2, you will need to specify a command-line argument (the name of the server, "localhost" in your case) in the Visual Studio project settings. However, I don't remember how to do this. It's somewhere in the Alt+F7 menu I think. EDIT: Here it is (probably a little different since this is VS 2003 apparently, and it looks like a .NET project) Avenging Dentist fucked around with this message at 20:33 on Jul 30, 2009 |
# ? Jul 30, 2009 20:22 |
|
Avenging Dentist posted:The client is probably exiting once it receives and prints the data. Since it's a command-line thing in Windows it'll close the command prompt almost immediately. The solution is to either 1) run it from Visual Studio (non-debug mode), since Visual Studio will insert a pause before it closes the prompt, 2) run it from Visual Studio in debug mode and set a breakpoint just before you return from main, or 3) open up a command prompt manually and execute the client program from there. OK sweet, I think I found where to write it in VS 2008 but how do you write the command to set the server? Google isn't much help for some reason.
|
# ? Jul 30, 2009 20:39 |
|
HondaCivet posted:OK sweet, I think I found where to write it in VS 2008 but how do you write the command to set the server? Google isn't much help for some reason. If you mean the value to fill in for the client's command-line argument, you literally just type localhost in that field. It'll make the client behave like you typed client.exe localhost at a command prompt, which is what the test app expects. The server app should run fine without any arguments passed in.
|
# ? Jul 30, 2009 20:46 |
|
Avenging Dentist posted:If you mean the value to fill in for the client's command-line argument, you literally just type localhost in that field. It'll make the client behave like you typed client.exe localhost at a command prompt, which is what the test app expects. Hooray it works now, thanks! So is this the right type of server/client pair to use for streaming data or is it going to explode if I try it?
|
# ? Jul 30, 2009 21:08 |
|
HondaCivet posted:So is this the right type of server/client pair to use for streaming data or is it going to explode if I try it? If the server will only ever have one client, that basic method should be sufficient. Otherwise, you'd want to look at the asynchronous version.
|
# ? Jul 30, 2009 21:22 |
|
Avenging Dentist posted:If the server will only ever have one client, that basic method should be sufficient. Otherwise, you'd want to look at the asynchronous version. What's the difference? It sounds like synchronous doesn't do anything until it gets a request but the asynchronous does? Also, what about connecting between computers? Is that another thing that has to be done in the command line?
|
# ? Jul 30, 2009 22:45 |
|
HondaCivet posted:What's the difference? It sounds like synchronous doesn't do anything until it gets a request but the asynchronous does? Synchronous communication is just the process of sending data immediately and not doing anything else while that's happening. Asynchronous communication sends stuff in the background, making it easier to handle multiple connections or to do other stuff while the transfer is happening. HondaCivet posted:Also, what about connecting between computers? Is that another thing that has to be done in the command line? With the sample code from Boost, yes. However, as long as you let Boost.Asio know what server you're connecting to, you can do it however you want. (Hard-coding, config file, GUI, etc).
|
# ? Jul 30, 2009 22:59 |
|
Adhemar posted:A double is usually 8 bytes, whereas a reference (essentially a pointer under the hood) would be only 4 bytes on a 32 bit machine, so it can reduce the amount of data that needs to be copied around. For int it doesn't really make sense, because it's only 4 bytes, while a pointer or reference is the same size, or even bigger (on a 64 bit machine). It's not the best of ideas though. Some platforms (like PowerPC or x86-64) will pass parameters in registers when possible but if you're passing a const reference to a primitive type some compilers will force it to the stack and pass the address which isn't anywhere near an improvement in performance.
|
# ? Jul 31, 2009 00:09 |
|
Adhemar and ehnus posted:answers Thanks guys. On similar lines, I've seen other code where class methods obtain members as (*this).membername or this->membername. Is this done to protect against potential naming conflicts? So that you always get the member membername and not something in a more local scope with the same name?
|
# ? Jul 31, 2009 14:05 |
|
DoctorTristan posted:Thanks guys. On similar lines, I've seen other code where class methods obtain members as (*this).membername or this->membername. Is this done to protect against potential naming conflicts? So that you always get the member membername and not something in a more local scope with the same name? Yes, that or they want to be
|
# ? Jul 31, 2009 17:01 |
|
Ledneh posted:Yes, that or they want to be More than likely they've become crippled by code completion and can't remember the names of member variables on their own.
|
# ? Jul 31, 2009 17:05 |
|
DoctorTristan posted:Thanks guys. On similar lines, I've seen other code where class methods obtain members as (*this).membername or this->membername. Is this done to protect against potential naming conflicts? So that you always get the member membername and not something in a more local scope with the same name? If you're in a class template member function definition and you need to access a member of a base whose type is dependent on a template argument you have to access that member explicitly otherwise your compiler will attempt to find the name during the first phase of name lookup and you will get a compile-time error, or worse, refer to the wrong thing. The same goes for accessing members of the base class from the child template definition (you need to qualify the name).
|
# ? Jul 31, 2009 18:03 |
|
That Turkey Story posted:(you need to qualify the name). Of course, it also works if you qualify it with a nested-name-specifier, but that tends to get verbose.
|
# ? Jul 31, 2009 19:42 |
|
What does everyone think about http://www.smallshire.org.uk/sufficientlysmall/2009/07/31/in-c-throw-is-an-expression/ ? It seems useful for writing range-checking code more tersely, as in the given example. I checked the standard and throw-expression has type "void", although it seems to have additional magic properties. For example:code:
code:
|
# ? Jul 31, 2009 22:06 |
|
Interesting: 1. http://codepad.org/Uih70A6G 2. http://codepad.org/09VrvGRb 3. http://codepad.org/sI4jbaAY
|
# ? Jul 31, 2009 22:34 |
|
floWenoL posted:I didn't find anything in the standard that talks about this (although I only looked at section 15). See 5.16p2 and 5.17p1.
|
# ? Jul 31, 2009 22:47 |
|
floWenoL posted:What does everyone think about http://www.smallshire.org.uk/sufficientlysmall/2009/07/31/in-c-throw-is-an-expression/ ? It seems useful for writing range-checking code more tersely, as in the given example. I checked the standard and throw-expression has type "void", although it seems to have additional magic properties. I'm pretty sure the behavior is described as a part of the ternary operator. Coincidentally, at Boostcon Doug Gregor and Sebastian Reidl briefly walked through some clang code for dealing with the ternary operator, including the throw expression behavior, to show off the elegance of the code-base. I think Sebastian had just recently written it at the time.
|
# ? Jul 31, 2009 22:52 |
|
Speaking of Clang, my current personal project is to teach myself LLVM and spicing up things through Boost.Proto to make the whole JIT experience more straight forward. The thought is that it should be trivial to compose and combine expression snippets easily in order to produce the end result lazily. Silly example:code:
code:
|
# ? Jul 31, 2009 23:55 |
|
I felt like I knew most of C++, until I discovered this perfectly valid C++ the other day (related to the throw stuff above).code:
|
# ? Aug 2, 2009 17:19 |
|
oldkike posted:I felt like I knew most of C++, until I discovered this perfectly valid C++ the other day (related to the throw stuff above). What does it do?
|
# ? Aug 2, 2009 20:27 |
|
|
# ? Jun 7, 2024 09:51 |
|
litghost posted:What does it do? Exactly what it looks like.
|
# ? Aug 2, 2009 20:35 |