1

Hello.
Earlier I decided that I would use the following programming languages: C#, Python, Java, PHP.
But now I'm thinking about developing MUD games.
There are a lot of popular and trusted libraries in C and C++.
Should I use C or C++ for my tasks?
Do I need a deep knowledge of C or C++ when using libraries or not?
Thanks in advance!

Thumbs up

2

Let me answer your questions, and advise you, too.
1. Use C++. C makes for very dirty implementations that are hard to use. Bad (or good?) thing is your going to be using it anyway.
2. Yes, indeed there are a lot -- and I do mean a lot! -- of libraries available out there. On Linux you have your standard POSIX sockets implementation. Then there's Boost.Asio, Poco, Dlib, and much more. I'll post an example of a socket writer in C++ below, as an example, as I find that that is the easiest to get comfortable with. This sample uses Boost.Asio:

//compile with g++ srcfile.cpp -lboost_system -pthread 

#include <boost/asio.hpp>

int main()
{
boost::asio::io_service io_service;
boost::asio::ip::tcp::socket sock(io_service);
boost::asio::ip::tcp::resolver resolver(io_service);
boost::asio::ip::tcp::resolver::query query("localhost", "4321");
boost::asio::connect(sock, resolver.resolve(query));
boost::asio::write(sock, boost::asio::buffer("Hello world socket\r\n"));
return 0;
}

In C, this looks like:

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

int main() {
int i, sock, len, slen;

struct addrinfo hints, *addrs;  
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;

   if (0 == getaddrinfo("localhost", "256", &hints, &addrs)) {
sock = socket(addrs->ai_family, addrs->ai_socktype, addrs->ai_protocol);
if ( sock >= 0 ) {
if ( connect(sock, addrs->ai_addr, addrs->ai_addrlen) >= 0 ) {
const char *pm = "Hello world!";
do {
len = strlen(pm);
slen = send(sock, pm, len, 0);
pm += slen;
} while ((0 <= slen) && (slen < len));
}
close(sock);
}
freeaddrinfo(addrs);
}
}

As personal preference, I do prefer Rust to C and C++:

// Echo server, handles (perhaps) only one connection, don't really know
use std::net::*;

fn handle_client(stream: TcpStream) {
loop {
let mut text = String::new();
stream.read_to_string(&text).expect("Failed to read TCP stream.");
stream.write (text.as_bytes());
}

fn main() {
let listener = net::TcpListener::bind("127.0.0.1:2500").expect ("Cannot bind to port 2500.");
for stream in listener.incoming() {
match stream {
Ok(s)=>handle_client(s),
Err(e)=>error!("IO Error: {}", e),
}
}
}

That's my personal preference though.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up

3

Hello.
But the point is, should I use C++ if I want to use predefined libraries or other languages. Should I be a C++ professional to work with libraries?

Thumbs up

4 (edited by Ethin 2018-01-06 08:51:39)

This question is very hard to answer and really depends on your personal preference. And, to be honest (and blunt), it seems like your switching languages a lot and can't find a good language to settle down with. I know the feeling, but if your going to make anything big and major you can't really sprinkle lots of different languages in it because that makes the compiler (that is, the person who's building the project) need far more dependencies. For instance, if you mixed C#, C, C++, and Rust in a single project, you'd need .NET/.NET Core, all the packages (Nu or via assemblies) to satisfy .NET or .NET Core, a C compiler capable of compiling both C and C++, all the C and C++ libraries which you used, the Rust compiler, and all the crates you used when using Rust. This is a symptom known as 'dependency hell'. Dependency hell is a colloquial term for the frustration of some software users who have installed software packages which have dependencies on specific versions of other software packages.
The dependency issue arises around shared packages or libraries on which several other packages have dependencies but where they depend on different and incompatible versions of the shared packages. If the shared package or library can only be installed in a single version, the user may need to address the problem by obtaining newer or older versions of the dependent packages. This, in turn, may break other dependencies and push the problem to another set of packages. Unlike the dependency hell described here where the user gets frustrated, the builder also runs into this problem; they have to build libraries, compilers, programs and tools, which may need other libraries, programs, tools, etc., and so on and so forth, until your building so much that you run out of disk space or you enter a dependency loop and go no further, which only causes a massive mess that you cannot recover from. I would highly advise that you find a language your comfortable with first, program in it for a few months, if not a few years, look up code examples, research it, and then start doing big projects in it. Only then will you alleviate this problem permanently. But if you interbreed multiple languages together, your *going* to run into dependency hell, whether you like it or not. .NET/.NET Core does not have this problem only because the different CLI/CLR languages can be safely mixed because assemblies are language-agnostic. You have clearly rejected C# in favor of others and, therefore, will not have this safety resolver.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up

5

Hello.
No, I don't want to use multiple languages in the same project. I'm interested in what I should have knowledge of C++ for using ready-made libraries. I don't want to develop from scratch. I know the basics, conditions, variables, loops, arrays, pointers, OOP in C++, is this knowledge sufficient?
I like using C# or Python, but I need a reliable tool for developing a server for Linux. For C++, there are many libraries and examples for my tasks, but I'm not sure that my knowledge is sufficient.
Thanks in advance!

Thumbs up

6

Yes, your knowledge is sufficient. Developing something like that from scratch is simply stupid, so use what libraries you have. To do something like this, find a good networking library or list of networking libraries (I'd recommend http://en.cppreference.com/w/cpp/links/libs as a highly-prised list) as a possible starting point. Look at examples and find what you feel most at home with.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up

7

hello
so you need recommendation for networking libraries
1. boost.asio
2. eNet
3. sdl2_net
4. kNet
5. curl (for http/ftp etc)
6. winsock (if you are using windows)
7. poco
8. openssl (for ssl and encryption)
9. crypto++ for encryption algorithms
10. happyhttp
11. tomCrypt for encryption/decryption
note these libraries all are not ment to be used specificly for mud, but might use them (boost.asio or sdl2_net)

bitcoin address: 1LyQ3hziMC2DTnCtgM3V1zfuZ73P3CYT9P

Thumbs up

8

I want to use one of the MUD engines. But I want to know that my knowledge of C++ is enough. Because many people told me that I have to know STL and many other tools. Stroustrup writes in his books that C++ is not suitable for those who want to use ready-made solutions.

Thumbs up

9

My problem is the choice between C and C++. Can I use C, etc.? It's a simple language, but it's difficult to develop on it. I do not know if I can use ready-made libraries.

Thumbs up

10

@jonikster, C++ and C are the same language with a few extras with C++. And that's not what he meant. You can develop ready-made solutions in C++ or develop with them.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up