I've been programming using scripting languages for nearly 7 years now. I don't have a background in computer science, rather in biology so I felt at home using Perl/Python/Bash for everything.
Now I want to use C++, taking advantage of strong typing to speed up my programs.
However, nearly everything I work with requires strings. For example, one of the basic file formats I work with is called a VCF, a tab-delimited text file.
Explain to me Sup Forumsents how come C++ does not have a simple split function for strings?!!!
WHY IS THERE NOT A FUNCTION IN THE STANDARD LIBRARY TO DO THIS SIMPLE TASK???!!!
In Perl
#!/usr/bin/perl open IN, $ARGV[0]; while(){ chomp; my @row = split /\t/, $_; print $row[3],"\n"; }close IN;
In Python
#!/usr/env python import sys with open(sys.argv[1]) as f: for l in f: row = l.rstrip('\n').split('\t') print row[3]
In C++ I'm using a split.cpp and split.h files compiled with another main.cpp. YOU WOULD THINK THERE WOULD BE A SIMPLE split FUNCTION BUT NO. I DON'T THINK THEY SPLIT STRINGS IN DENMARK. FUCK C++
> Explain to me Sup Forumsents how come C++ does not have a simple split function for strings?!!!
Because if you are 2 retarded to implement this you're self, then you should just kys yourself :^)
James Ramirez
split.h #ifndef __SPLIT_H #define __SPLIT_H
// functions to split a string by a specific delimiter #include #include #include #include // split a string on a single delimiter character (delim) std::vector& split(const std::string &s, char delim, std::vector &elems); std::vector split(const std::string &s, char delim);
// split a string on any character found in the string of delimiters (delims) std::vector& split(const std::string &s, const std::string& delims, std::vector &elems); std::vector split(const std::string &s, const std::string& delims);
main.cpp #include #include #include #include #include "split.h" using namespace std; int main(int argc, char* argv[]) { if (argc < 2) { cerr
Grayson Perez
Use pure C
Nolan Martin
I bet it's waaaaay easier in pure C >not
Blake Watson
Any programmer worth a shit can write the entire standard library of their language of choice by themselves.
The point is that they shouldn't have to. A programmer's time is better spent solving new problems instead of rewriting elementary functions for every project he works on.
Charles Diaz
Use Rust. C++ is a legacy, poor-designed, bloated language and shouldn't be used for new projects.
Asher Bell
>Use Rust. C++ is a legacy, poor-designed, bloated language and shouldn't be used for new projects. Serious question. How do you compile Rust lang?
C/C++ is still widely used in science so writing a new tool using a lang that's not so popular runs the risk of it never being used (and thus your scientific career ends if you don't get those citations)
Nathaniel Ortiz
if you really cared about performance and string splitting is a critical part of your program you're better off writing your own tuned to your use cases anyways
Carter Davis
I'm slowly realizing this.
Daniel Cox
>Serious question. How do you compile Rust lang? Using rustc, of course.
>C/C++ is still widely used in science so writing a new tool using a lang that's not so popular runs the risk of it never being used (and thus your scientific career ends if you don't get those citations) I don't work in the academia so I can't give any meaningful opinion. I would assume the choice of the language wouldn't matter (being just means to an end), but if you think the popularity of the language you use will affect the popularity of your paper then, sure, stick to C++.
Juan Morgan
Has to do with refereeing and people checking your work.
If the referees or people judging the quality of your work can't compile your code/emulate it, then people won't know shit about it. In other words, it won't be verified or they'll drag their feet to verify shit.
If I suddenly started doing all of my code in Mathematica, despite MATLAB being the standard, my lab's research papers won't even get a second look. People aren't going to spend time learning a new language when the "standard" is already there.
Academia is not like the industry. In industry, you're propelled to learn new languages and technologies; in academia, there are so many new papers/theorems/concepts that it's best to stick to one 'standard' (in this case, C++ or MATLAB) and write/publish code using that.
t. grad student who shares the OP's frustrations.
Landon Brown
What's your field? I'm in genetics in my 4th year as a PhD student
James Brooks
I lost all respect for C++ after this.
Brody Baker
explain?
Jaxon Taylor
>225x225 Considering that you're too dumb to differentiate between thumbnails and proper images I suggest that you give up programming altogether.
Brody Carter
>you wouldn't understand my art
Samuel Bennett
go back to Sup Forums
Ayden Gonzalez
What does this have to do with pole?
Henry Harris
:^)
Jaxon Martin
...
Brandon Bailey
And this, my friends, is why you should fucking start with C or C++ so you are not trained into the "libraries are magic" or "it's just 3 lines in python" mindest, as someone just magically designed the language that way.
Brayden Russell
...
Aaron Robinson
(you) vs (the guy she told you not to worry about)
Easton Wright
Another one haha
Jason Roberts
...
Wyatt Rogers
What is "sucking eggs", is this a new thing the kids are saying?
You're ruining this thread btw thanks.
Leo Lopez
Couldn't you share the core algorithm as pseudocode, and distribute as dynamically linkable binaries if you are worried about people being willing to do all the ludicrous troubleshooting necessary to compile C++ header libraries, but unwilling to explore a new language?
If them downloading the rust compiler is fine, you can distribute your code as a crate (package), and then installing your crate is just "cargo install cratename" in the terminal and cargo will download the sources and compile everything for the user.
Kevin Edwards
>Explain to me Sup Forumsents how come C++ does not have a simple split function for strings?!!! Because C++ is meant for developing operating systems. It's not meant for your shitty script kiddie needs. Anyone worth their shit could quite easily implement a split function.
Michael Evans
Funny Enough I'm OP >winfag at work unfortunately
Cooper Foster
Bluh. Having tried Mathematica and matlab, I genuinely feel sorry for you if you are stuck with matlab. It was the worst language that I've ever used, and I was forced to use it during all my undergrad years. I dropped it in favour of Mathematica as soon as I got the chance.
Leo Morales
whoops had some personal info on that one
Logan Watson
Just use boost::split
Don't listen to anyone that tells you that boost is bad. It is the real standard library of C++, the one that makes the language remotely usable.
Jacob Walker
C++ is shit but not for the reasons you see user. String processing does suck but there's plenty of string processing functions in C++ but split is a rather special case for performance oriented programs. You can use to achieve your goal without being too verbose.
I don't find your reason for using C++ compelling. There's other languages with static typing that's more suitable and static typing doesn't gain you that much really. C++ isn't a language you use to simply gain performance. You need to put work into it. It's an environment that lets you write efficient programs.
If you want a language that makes it fairly easy to write efficient programs without too much effort java is pretty good. Getting to the peak of performance risk very difficult though and has you spend time tuning the virtual machine. But your attitude towards this tells me you won't do that and you will simply enjoy the benefits of Java over C++.
It's not for you. People who use C++ or C does it because they need to. They have concerns that force them into it. It's never a language you prefer naturally. You use it when you have needs others can't fill.
Josiah Reyes
>If them downloading the rust compiler is fine, you can distribute your code as a crate (package), and then installing your crate is just "cargo install cratename" in the terminal and cargo will download the sources and compile everything for the user. Damn the Rust shills are in full force.
Isn't this the purpose of a MakeFile for C/C++?
the only time I had issues installing software for research written in C/C++ is when BOOST was used so No I can't really use BOOST unless I really don't want people to use my code
Xavier Garcia
dont worry friend, I'll repost it for you :)
Oliver White
>boost user should use boost. Nobody who uses C++ for anything serious should inflict boost upon themselves.
Hudson Long
C++ was a mistake
Brody Anderson
I used Java in undergrad and I still hate the syntax
Ryan Edwards
>enjoy the benefits of Java over C++. wouldn't bet on it
he'll kill himself as soon as he stumbles across Java EE even reflection or aspectj could land a deadly blow
Owen Howard
>SUCK_EGGS.jpeg >GO_SUCK_AN_EGG.jpeg >ALLAH.gif
Christian Smith
enjoy your B&
Jacob Bell
Doesn't matter what op picks really c++ isn't for him. You think user here is the kind of dude that requires reflection after having worked in scripting languages for 7 years?
Matthew Price
Make isn't a package manager with a central repository so no.
Easton Cooper
>reflection could you explain reflection?
Also please refer to the OP where I said I'm a biologist. I really don't need to use complex data structures for 90% of my work.
there's some optimization I can benefit from using a lang like C/C++
Nolan Long
None of you faggots ever heard of stringstream I suppose.
Brayden Rogers
Have you considered Julia? You get to keep the speed, without losing the advantages of a scripting language.
Alternatively, you could try using nonstandard implementation of Python such as PyPy or Cython.
Ayden Roberts
Don't use C++. Its literal cancer. Should never have been invented.
Lincoln Torres
en.m.wikipedia.org/wiki/Reflection_(computer_programming) Explains better than I do. These are features commonly missing in a lot of scripting languages and overall they're not that useful for what you do in scripting languages. It tends to be useful where you have very large systems projects. Because it automates what would otherwise be a rather onerous process.
Luis Rodriguez
>there's some optimization I can gain from using C/C++ Thing is that with C/C++ you're not given that much for free. I'm sure your requirements are that super high that you feel the need to spend days on optimising pieces of code or writing SIMD. You just want to express your intent and have it be fast. C/C++ does get you some of that when you're in the right mindset but other languages get you there cheaper. The naive implementations in C/C++ aren't all that good.
Julian Sanchez
here's a shorter version int main() { std::string str_to_split("ab cd ef"); std::string pattern = ""; std::regex reg_pattern(pattern); std::sregex_token_iterator begin(str_to_split.begin(), str_to_split.end(), reg_pattern, 0); std::sregex_token_iterator end;
for (;begin != end; ++begin) { //do whatever you want with your string std::cout
Aiden King
Maybe, but OP probably spent more time creating this thread than it would have taken to create the function he needs.
Nolan Barnes
I use Cython and it's great.
Another reason to learn C++ is to pad my CV with some skills.
Lincoln Hill
I actually did both because I'm not a stupid neckbeard python scriptkiddie
You're experiencing a language made with a different philosophy in mind. You're used to getting a string and then splitting it, in C++ you're supposed to get your string in parts in the first place.
Evan Nguyen
It's (C)ancer++
Eli Watson
use std::env; use std::fs::File; use std::io::BufReader; use std::io::prelude::*; use std::path::Path;
fn main() { let path = Path::new(env::args().next().expect("Error: No arguments given!") ); let file = File::open(&path).expect("Error: Could not open file.")
let reader = BufReader::new(file); let lines = reader.lines();
for line in lines { let row = line.split("\t"); println!("{}", row.nth(3).expect("Error: Not enough fields in row!") ); } }
Also if your file has an ungodly number of fields per row, this doesn't create an intermediate vector for each row if you don't explicity tell it to. Everything is an iterator.
Jaxon Powell
>hating a language you barely know Typical Sup Forums. vector split(string src) { vector res; copy(istream_iterator(istringstream(src)), istream_iterator(), back_inserter(res)); return res; }
Cooper Foster
Now this is cool, thanks. Been looking for something like this.
Ayden James
What personal info?
William Brown
#include #include using namespace std;
vector split(string s, string k){ vector spl; spl.push_back(""); int i=0,j=0,off=0,is=0; while (s[i+off]!='\0'){ if (s[i+off]==k[j]){ off++; j++; if (j==k.size()){ spl.push_back(""); i+=off; j=0; off=0; is++; } } else{ spl[is].push_back(s[i]); j=0; off=0; i++; } } return spl; }
int main(){ vector r=split("gas the kikes race war nao" ," "); for (int i = 0; i < r.size(); i++){ cout
Grayson Barnes
Just use cython or numpy you fucking triple nigger
Michael Barnes
>oh boy I get to waste my time impementing trivial functions all day some of us value our time
Jeremiah Richardson
McCaroll itinerary. What is mccaroll?
Landon Richardson
>the pol boogeyman
Guess Sup Forums is infested with libtards too
Tyler Roberts
you seriously are some dumb nigger cattle.
the reason why nothing similar to a split exists in c++ is because it has tier python level performance.
be a real white man and build your own tokenizer where you return the length and location of the string, combine it with a compare string with length parameter and you aren't just another dumb cia nigger.
Landon Ortiz
He's a scientist we are hosting for a talk.
Does Terry code in C++?
Landon Fisher
doxxxxed and reported to your place of work
Landon Wood
>writing code in a header
stop this now
Cameron Brooks
funny because I lifted this from a well known API in biology