/dpt/ - Daily Programming Thread

Old thread: What are you working on, Sup Forums?

Other urls found in this thread:

pastebin.com/QD4CdThP
twitter.com/SFWRedditImages

>the same shitty reposted anime OP
This thread is just as bad as the frog OP.

New thread:

See >

C++ cannot enumerate foreach. It's been HALF A FUCKING CENTURY LMAO
foreach(index, number; numbers)
if (number == some_value)
return index;

Who really cares? C++ is garbage anyway, and you shouldn't be using it.

Which languages enumerate in foreach loops?

C#, D and Rust, top of my head

Python

Nim can do it too

So does Chapel, and fucking Go lol

haskell
head . dropWhile (/=some_value) $ numbers

lisp
(find some-value numbers :test #'=)
>foreach
map is better desu

Isn't the whole point of foreach that you don't care about the index and are just abstracting it away? It's like using a reference because you don't like pointers and then complaining that you can't do pointer arithmetic on it.

C# documentation tells me you need to manually maintain a counter variable.
D just appears to support it naturally, for plain arrays at least, which is kind of magic. Good job, D.
Rust makes you explicitly call an enumeration. Could use the same pattern in C++.

Not if the indices matter, which is the whole point of this exercise.

I know map is better but what do remember C++ is an OOP language

Working on a wayland compositor backend. It's still just drawing cats.
Video of a screen, because it currently has no way of screenshotting or recording yet.

This is retarded.
Why would you use foreach when you're trying to find an element.
for-each implies do something with each item, most likely IO
finding an element in a list or array should be a standard library function

nice work user

Are you the C-fag I jabbed at for using C?

Yes, probably.

>for-each implies do something with each item, most likely IO
foreach(index, line; lines)
writefln("%ds\t%s", index, line) ;
Guess what this does

Real thread:

Fuck off, reddior. Nobody cares.

Fuck off, frog shitter

>frog
nope
then use a for loop, lmao
for (int i = 0; i < array.length(); i++)
{ System.out.printf("%ds\t%s", i, array[i]);

Ugly and disgusting. Why not use a fucking while loop then?

...

>for (int i = 0; i < array.length(); i++)
> { System.out.printf("%ds\t%s", i, array[i]);
And people hate rust, perl, Haskell and PHP for too many syntax and symbols

for element in list:
index = list.index(element)

I'd just like to interject for a moment. C++ is a multi-paradigm language with a heavy emphasis on object-oriented programming, and it is trivial to implement map in C++.

C++ is literally C + Objects lmao

>Blah blah blah C++ support POO blah blah
So basically, it's shit.

s/real/frog/g

>user actually believes this

Dude, printing the index of an array item is trivial and having a special construct for it is retarded.
The only pros is that you saved some chars from being written.

Not just for supporting OOP, because of the fact that OOP is supposed to be C++'s essence. B*arne created C++ for OOP programmers

Because in a while loop it's easy to forget to increment the counter.

And templates, and function overloading, and default arguments, and non-nullable references, and namespaces, etc, etc.

Virtually every language supports OOP though.

My point is that if you are going to have a foreach loop, make a real foreach loop, not a neutered down half assed for loop.

I bet C++ foreach loops can't have custom index increment and reverse looping. It's there just as a placebo

you are looked down on by C++ devs

Why not just use J*va then lol?

C++ devs are on the bottom on the barrel

Who the fuck knows, C++ is for POO programmers that think they are too smart for Java

>templates
C++ templates are shit. Massive bloat, undecidable parsing, shitty syntax, terrible errors.
>function overloading
Useless and shit.
>default arguments
Useless.
>non-nullable references
C++'s invisible references are a fucking travesty, and encourage invisible state changes. NEVER use C++ references, or even C++ at all.
>namespaces
Also useless.

LOL fucking retarded rustfag, you're fucking deluded if you think you're convincing anyone to switch from C++ to rust, and now you've shown your absolute incompetence by claiming that C++ is an OOP language and that it's "C with classes"

You're right, why the fuck did they even add that half assed construct.

I'm not convincing you to use Rust and neither I use Rust myself. But I do believe C++ is worse than Rust

C#
var ind = MyList.IndexOf(MyList.Where(x => x == SomeValue).First())

rust can't do this

for(auto &item : std::as_const(vec))

Went from Java to C++
Are there any good guides on how to into pointer vs value assignment? I have a pretty good textbook but its either really lacking in that regard or I'm a dumbass, frankly probably both.

>std::as_const
PUKE

Wrote a little snippet of code on my phone while waiting for commencement to end...

pastebin.com/QD4CdThP

holy shit, kill yourself

C++ is the epitome of garbage, no language, not even Java can be worse than that shit

Yes it does
fn main() {
let vec = vec![2, 3, 5, 7, 11];

for &v in &vec {
println!("{}", v);
}
}
>std::as_const
AHAHAHAHAHAHAHAHAHHA

t. pajeet

C++ has a history, tends to create half assed implementation of things, a few decades pass and everyone rushes on to finish the implementation

I don't use POO language

>Programming on a phone
That sounds fucking awful.

>D just appears to support it naturally, for plain arrays at least, which is kind of magic. Good job, D.
Java goes further and allows you do use lists or regular arrays. Which is shocking for Java to do something well.

Ruby must be so slow lmao.

C++ is worse than Java

I'll do you one better: I used Vim.

No, Java works the same way as C++ and (as far as I can tell) C#. There's no automatic way to get the index in a Java foreach loop.

Do you have a physical keyboard on your phone or maybe a little bluetooth keyboard?
Otherwise that's just masochistic.

At that point you might as well just do
int i = 0;
foreach(/*...*/) {
// ...
i++;
}

std::for_each

Oh yeah. There is an easier way
var ind = MyList.IndexOf(SomeValue);


Too clever for my own boots, thanks user :)

Nah. Just hackers keyboard. But I mean... I was REALLY bored. Anyways, I think it's time I can blow this pop stand. The baccalaureates just got their degrees, so this shit is over.

That's even uglier and shittier, user

>2 foreach loops
keke

yfw is still shorter and FAR more efficient than your 'clever' solution

>O(n^2)

>O(n)

everybody is stupid except for me

Yes now head to >>>/plebbit/

they just have a bad habit of pretending to be retarded for the attention

If you learn C++, maybe I will.

I don't use windows and I don't intend to. I'd rather learn and use Java over C++

The code snippets resolve to the same thing to the compiler, just depends if the codebase you're working in prefers linq or loops and if you care about the minor extension-method overhead.

You would actually space out the Linq version a little better in production environment

var ind = MyList.indexOf(
MyList.Where(/*..*/)
.PipeLine2()
.PipeLine3()
.First()
);


with single pipeline code the foreach will always be easier, with multipipeline it becomes a proper question to ask

>muh "look mom, i can do it in one line"
>meanwhile it bumps up the complexity by a factor of n
>meanwhile it actually has more writing than if you were to just keep track of the number like a sane person who doesn't have a myopic fixation over LoC

> (define add1 (lambda (x) (+ x 1)))
> (add1 0)

I started learning Scheme last week and have been really enjoying it.

>Duplicate functionality: the language

for i in lst:
for k in range(len(lst) + 1):
j =lst[k]
if j == i:
index = k

Yes, that's C++ in a nutshell. Unavoidable, really.

Wait till you find out how inefficient it is.

>The code snippets resolve to the same thing to the compiler
I don't know anything about compiler optimizations but I'm having a hard time believing that the compiler is smart enough to figure that out. Got any source/proof? eg: have you tried writing those different code snippets and gotten the same CIL?

Even still, my way is easier to read because it doesn't try to be cute, and it's expressed in fewer characters.

so I'm thinking of making a simple bittorrent client in Rust. kinda meh huh? would that be at all impressive on a resume? I have no original ideas, I know there are tens of thousands of amateur shitty bittorrent programs out there. I'm not applying to big companies, I just need something that shows I know basic programming concepts and can learn.

How does one know when its okay to be inefficient.
For example, I'm using a higher level language, and I'm wondering if its okay to do things that traverse a list at least 6 times per call.

>I have no original ideas,
Write a window manager for wayland

You can go on about this stupid shit all you want, but it's note even correct.
[10, 20, 30, 20, 40]
1: 10
2: 20
3: 30
2: 20
5: 40

>note
not*

Is there a lazy lisp out there.

meanwhile, rust omits basic functionality like C-style for loops, and delusional rust users expect it to replace C and C++

Probably because Rust has a foreach loop that's not a shitty placebo (like C++)

D's foreach loop is a flagship loop. It nullifies the usage of classic C99 for loops

> Even still, my way is easier to read because it doesn't try to be cute, and it's expressed in fewer characters.

> with single pipeline code the foreach will always be easier, with multipipeline it becomes a proper question to ask

Reading comprehension.

I googled for my source but couldn't find it. The CIL will be different due to extension method overhead. Native foreach will always be quicker than extension method way. There's never been a case where I've cared about CPU time optimisation and I CERTAINLY don't care about space-on-disk optimisation for the code since the run time environment and assets take a dump on the small amount my code adds.

>D
Literally nobody cares. Why did you even bring that irrelevant shit up?

Rust has a good macro system unlike C. You can literally emulate C loops if you want to

Sad that your "relevant shit" is worse than the irrelevant one?

I can't stand not knowing how things work under the hood.
I think I should learn C.

ASM*