C++ SUCKS

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++

>general C/C++ hate thread

Other urls found in this thread:

en.m.wikipedia.org/wiki/Reflection_(computer_programming)
github.com/vcflib/vcflib#vcflib
twitter.com/SFWRedditVideos

> 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 :^)

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);

template < class ContainerT >
void tokenize(const std::string& str, ContainerT& tokens,
const std::string& delimiters = " ", const bool trimEmpty = false)
{

std::string::size_type pos, lastPos = 0;
while(true)
{
pos = str.find_first_of(delimiters, lastPos);
if(pos == std::string::npos)
{

pos = str.length();

if(pos != lastPos || !trimEmpty) {
tokens.push_back(typename ContainerT::value_type(str.data()+lastPos, (typename ContainerT::value_type::size_type)pos-lastPos));
}

break;
}
else
{
if(pos != lastPos || !trimEmpty) {
tokens.push_back(typename ContainerT::value_type(str.data()+lastPos, (typename ContainerT::value_type::size_type)pos-lastPos));
}
}

lastPos = pos + 1;
}
};


#endif

split.cpp
#include "split.h"


std::vector &split(const std::string &s, char delim, std::vector &elems) {
std::string delims = std::string(1, delim);
tokenize(s, elems, delims);
return elems;
}

std::vector split(const std::string &s, char delim) {
std::vector elems;
return split(s, delim, elems);
}

std::vector &split(const std::string &s, const std::string& delims, std::vector &elems) {
tokenize(s, elems, delims);
return elems;
}

std::vector split(const std::string &s, const std::string& delims) {
std::vector elems;
return split(s, delims, elems);
}


main.cpp
#include
#include
#include
#include
#include "split.h"
using namespace std;
int main(int argc, char* argv[])
{
if (argc < 2) { cerr

Use pure C

I bet it's waaaaay easier in pure C
>not

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.

Use Rust. C++ is a legacy, poor-designed, bloated language and shouldn't be used for new projects.

>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)

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

I'm slowly realizing this.

>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++.

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.

What's your field?
I'm in genetics in my 4th year as a PhD student

I lost all respect for C++ after this.

explain?

>225x225
Considering that you're too dumb to differentiate between thumbnails and proper images I suggest that you give up programming altogether.

>you wouldn't understand my art

go back to Sup Forums

What does this have to do with pole?

:^)

...

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.

...

(you)
vs
(the guy she told you not to worry about)

Another one haha

...

What is "sucking eggs", is this a new thing the kids are saying?

You're ruining this thread btw thanks.

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.

>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.

Funny Enough I'm OP
>winfag at work unfortunately

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.

whoops had some personal info on that one

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.

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.

>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

dont worry friend, I'll repost it for you :)

>boost
user should use boost.
Nobody who uses C++ for anything serious should inflict boost upon themselves.

C++ was a mistake

I used Java in undergrad and I still hate the syntax

>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

>SUCK_EGGS.jpeg
>GO_SUCK_AN_EGG.jpeg
>ALLAH.gif

enjoy your B&

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?

Make isn't a package manager with a central repository so no.

>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++

None of you faggots ever heard of stringstream I suppose.

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.

Don't use C++. Its literal cancer.
Should never have been invented.

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.

>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.

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

Maybe, but OP probably spent more time creating this thread than it would have taken to create the function he needs.

I use Cython and it's great.

Another reason to learn C++ is to pad my CV with some skills.

I actually did both because I'm not a stupid neckbeard python scriptkiddie

std::vector tab_split(std::string s)
{
size_t start=0;
size_t end=s.find_first_of('\t');

std::vector output;

while (end

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.

It's (C)ancer++

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.

>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;
}

Now this is cool, thanks.
Been looking for something like this.

What personal info?

#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

Just use cython or numpy you fucking triple nigger

>oh boy I get to waste my time impementing trivial functions all day
some of us value our time

McCaroll itinerary. What is mccaroll?

>the pol boogeyman

Guess Sup Forums is infested with libtards too

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.

He's a scientist we are hosting for a talk.

Does Terry code in C++?

doxxxxed and reported to your place of work

>writing code in a header

stop
this
now

funny because I lifted this from a well known API in biology

github.com/vcflib/vcflib#vcflib

No, he writes in holyc, his own version of C

wasn't perl mostly written to do shit with strings

yes and that's why it was heavily used in biology. Now python is the language of choice.

But all the heavy lifting tools are written in C/C++

With the exception of one program written in Java (GATK)

you do realize that templated functions cannot be defined in a separate objects right?

You are forced to put them in header files

I'm learning

>What is strtok?

>C++

not saying it doesn't but even C has shit like strtok and c++ has a full blown stream standard lib that I'm sure can do this for you.

how do you think that getline() bullshit works?

You might like Java better, it's pretty much the fastest language that doesn't require a shit load of obnoxious bullshit.