Originally posted by darkonix
View Post
Rust-Based, Memory-Safe PNG Decoders "Vastly Outperform" C-Based PNG Libraries
Collapse
X
-
Last edited by sdack; 12 December 2024, 10:50 AM.
-
-
Originally posted by sdack View PostIt is not progress what I was describing, but human nature. Progress is just something we do. People do not necessarily choose the things they should in theory. You do not see people adopting veganism when it is healthier and better for the environment. Alcohol causes countless deaths each year, and still people drink. Do you think people will drop alcohol, start to eat vegan, lower their sugar intake and do daily exercises, because it is the right thing to do? People choose what they find practical, and converting to Rust is an inconvenience.
Rust also has some very nice dependencies for achieving things that show up commonly in "scripting" tasks, like Serde, Clap, Rayon, ignore, etc. and they're dirt-simple to add to a project.Last edited by ssokolow; 12 December 2024, 10:58 AM.
Comment
-
-
Originally posted by lowflyer View Post
Sorry back2未來 , But this blurp is not C++. It is plain ole' C code with a bit of adaption to use C++ libraries. You got that with the help from some "cpp expert", you say? He lied to you. A mere change from `gcc` to `g++` does not convert your C code into C++.
Code:#include <iostream> #include <string> #include <functional> #include <sstream> #include <boost/asio.hpp> #include <nlohmann/json.hpp> using json = nlohmann::json; namespace asio = boost::asio; using boost::asio::ip::tcp; // Function to handle HTTP GET request and fetch JSON data void fetch(const std::string& host, const std::string& path, const std::function<void(const json&)>& callback) { if (host.empty() || path.empty()) { std::cerr << "Error: Empty host or path provided" << std::endl; return; } if (!callback) { std::cerr << "Error: Invalid callback function provided" << std::endl; return; } try { asio::io_context io_context; // Resolve host tcp::resolver resolver(io_context); auto endpoints = resolver.resolve(host, "http"); // Create socket and connect to host tcp::socket socket(io_context); asio::connect(socket, endpoints); // Prepare the HTTP GET request std::stringstream request_stream; request_stream << "GET " << path << " HTTP/1.1\r\n" << "Host: " << host << "\r\n" << "Connection: close\r\n\r\n"; // Send the request asio::write(socket, asio::buffer(request_stream.str())); // Receive the response std::string response; asio::streambuf buffer; //asio::read_until(socket, buffer, "\r\n\r\n"); asio::read_until(socket, buffer, "}" ); // Process response headers (skip them) std::istream response_stream(&buffer); std::getline(response_stream, response); // First line is the HTTP status std::string header; while (std::getline(response_stream, header) && header != "\r") { // Skipping the headers } // Read the body of the response std::ostringstream body_stream; //asio::read(socket, buffer, asio::transfer_all()); body_stream << &buffer; // Parse the JSON data from the response body std::string body = body_stream.str(); if (body.empty()) { std::cerr << "Error: Received empty response body from " << host << path << std::endl; } else { try { json jsonData = json::parse(body); callback(jsonData); } catch (const json::parse_error& e) { std::cerr << "Failed to decode JSON from " << host << path << ": " << e.what() << std::endl; } } } catch (const std::exception& e) { std::cerr << "Exception while fetching data "<< e.what() << std::endl; } } int main() { // Example usage of fetch fetch("worldtimeapi.org", "/api/ip", [](const json& data) { if (data.is_null()) { std::cerr << "Error: Received null JSON data" << std::endl; return; } std::cout << "Received data: " << data.dump(4) << std::endl; }); return 0; }
Comment
-
-
Originally posted by darkonix View PostThere is a point there: it is still valid C++, right?
Comment
-
-
Originally posted by sdack View PostC++ is a superset of C. It is perfectly fine for code to look like C in C++. One does not have to use every single feature of C++ on each line. If one can solve a problem with a few lines of C code inside a C++ application then it was done correctly. I have seen idiots who try to solve every problem with templates, because they were just having fun. There are often many ways one can solve a problem, but idiotic code is much harder to maintain. Keep it simple. Do not listen to the bullshitters.
If your C++ code is really C, then you should just write C code... You'll get better results...
EDIT: I really don't understand why people even write in C++ at all, it is not fast, or intuitive, or readable... It is convoluted, overly complex and hard to learn...
EDIT: Even in this thread there are a few guys shaming new graduates because they don't fully understand C++, but even with their claimed 40+ years experience, I absolutely guarantee even they don't come anywhere even close to fully understanding C++. Not even the guys defining it and writing the compiler for it fully understand it or else it would perform better!Last edited by duby229; 12 December 2024, 02:12 PM.
Comment
-
-
Originally posted by duby229 View Post
You do know gcc outperforms g++, right? And by huge margin on a few metrics too. Gcc compiles like 5 times faster than g++, it produces considerably smaller file sizes, it generates faster binaries.
If your C++ code is really C, then you should just write C code... You'll get better results...
EDIT: I really don't understand why people even write in C++ at all, it is not fast, or intuitive, or readable... It is convoluted, overly complex and hard to learn...
EDIT: Even in this thread there are a few guys shaming new graduates because they don't fully understand C++, but even with their claimed 40+ years experience, I absolutely guarantee even they don't come anywhere even close to fully understanding C++. Not even the guys defining it and writing the compiler for it fully understand it or else it would perform better!Last edited by darkonix; 12 December 2024, 11:45 PM.
Comment
-
-
Originally posted by sdack View PostSo much anger and ignorance!
Originally posted by sdack View PostIf the Rust people were not stupid, they would not need to be protected from mistakes in the first place.
Originally posted by sdack View Post
Also, seat belts protect from the mistakes of other drivers. And only to add this: FUCK.
you don't say
re-read the sections i've split up in sequence and think about it
Comment
-
-
Originally posted by duby229 View Post
You do know gcc outperforms g++, right? And by huge margin on a few metrics too. Gcc compiles like 5 times faster than g++, it produces considerably smaller file sizes, it generates faster binaries.
it is not like c doesnt come with a cost. i can count, on one hand, the number of rust applications which have crashed on me. c though... there's a few that are good: linux, systemd etc, but that's because the standards are so high. most applications do not have the resourcing to meet the same standards. providing the same standards in c++ though reduces the resource effort because you suddenly get tons of features which you don't have to reimplement yourself. providing the same standards in rust is even much easier than c++ and more accessible to Not Perfect people who might be writing some code at 2am since they have a job and that's just what happens sometimes.
Comment
-
-
Originally posted by sdack View PostC++ is a superset of C. It is perfectly fine for code to look like C in C++. One does not have to use every single feature of C++ on each line. If one can solve a problem with a few lines of C code inside a C++ application then it was done correctly. I have seen idiots who try to solve every problem with templates, because they were just having fun. There are often many ways one can solve a problem, but idiotic code is much harder to maintain. Keep it simple. Do not listen to the bullshitters.
Example (from a quick google search):
Code:#include <stdlib.h> int main() { // C++ error: invalid conversion from 'void*' to 'int*' int *p = malloc(sizeof(int)); free(p); }
Comment
-
-
Originally posted by darkonix View Post
C++ is not a strict superset of C. Some code compiles in C that does not in C++.
Example (from a quick google search):
Code:#include <stdlib.h> int main() { // C++ error: invalid conversion from 'void*' to 'int*' int *p = malloc(sizeof(int)); free(p); }
Comment
-
Comment