[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 334
Thread images: 30

File: 1443604195353.jpg (125KB, 800x720px) Image search: [Google]
1443604195353.jpg
125KB, 800x720px
What are you working on, /g/?

Old thread: >>59623850
>>
first OwO
>>
second!
>>
If your language has GC, then its performance is necessarily inferior to C/C++/Rust, and you cannot use performance as an argument for using it.
>>
>>59628171
trying to solve a problem i've created using algorithms that are way beyond my capacity
>>
>>59628188
That's not a strawman really. D is designed such that most "obvious" code is fast and safe. On occasion a function might need to escape the confines of type safety for ultimate speed and control. For such rare cases D offers native pointers, type casts, access to any C function without any intervening translation, manual memory management, custom allocators and even inline assembly code
import core.stdc.stdlib;

void livingDangerously()
{
// Access to C's malloc and free primitives
auto buf = malloc(1024 * 1024);
// free automatically upon scope exit
scope(exit) free(buf);
// Interprets memory as an array of floats
auto floats = cast(float[]) buf[0 .. 1024 * 1024];
// Even stack allocation is possible
auto moreBuf = alloca(4096 * 100);
//...
}

// Using inline asm for extra speed on x86
uint checked_multiply(uint x, uint y)
{
uint result;
version (D_InlineAsm_X86)
{
// Inline assembler "sees" D variables.
asm
{
mov EAX,x ;
mul EAX,y ;
mov result,EAX ;
jc Loverflow ;
}
return result;
}
else
{
result = x * y;
if (!y || x <= uint.max / y)
return result;
}
Loverflow:
throw new Exception("multiply overflow");
}

void main()
{
// ...
}
>>
File: wew2.jpg (118KB, 1100x698px) Image search: [Google]
wew2.jpg
118KB, 1100x698px
Friendly reminder that if your language doesn't have a specific data structure, it doesn't exist and asking people to "make it themselves" is not a valid engineering advice in 2017 where downloading a library for one function is faster than learning to implement it yourself.
>>
>>59628171
cirno is cute!
>>
>>59628233
Download me a regex parser for x86 assembler
>>
I was at the hospital today and had a camera shoved up my dick, it hurts like hell now and I can't concentrate on programming.
wat do, /g/?
>>
Is it advisable to store non-pointer values in a pointer?
>>
>dude just implement it yourself lmao

c apologists are awful
>>
>>59628282
>c
Literally no one cares
>>
>>59628282
You know there's plenty of libraries you can access from C that does 99% of basic shit.
>>
>>59628223
I suggest that such cases are not rare.

So, if you want performance, you have to use an ugly wrapper around C? Why not just use C++ and benefit from more consistent code and more mature tooling and ecosystem? After all, in C++ most "obvious" code is also safe and actually fast.
>>
>>59628275
Yes, this is an excellent idea, very good.
>>
>>59628212
https://togototo.wordpress.com/2013/08/23/benchmarks-round-two-parallel-go-rust-d-scala-and-nimrod/
https://github.com/kostya/benchmarks/blob/master/README.md
https://attractivechaos.wordpress.com/2011/06/22/my-programming-language-benchmark-analyses/

Wow, just look at those inferior speeds
>>
>>59628275
what do you expect to be told
>>
>>59628275
how do you ever store non-pointer values in a pointer?
>>
>>59628275
No, you should never store anything in a pointer
>>
>>59628307
int *ptr = 14;
>>
>>59628307
You can do it with C unions.
>>
>>59628295
>its okay when c does it
>its not okay when JS does it
>>
>>59628324
well, that's a segfault.
>>
File: comp guy2.png (926KB, 1225x935px) Image search: [Google]
comp guy2.png
926KB, 1225x935px
this guy is fucking EPIC
>>
>>59628334
int *ptr = "hello world";
>>
File: 1490320518786.jpg (25KB, 433x380px) Image search: [Google]
1490320518786.jpg
25KB, 433x380px
>Programming in C means you are using an unsafe memory model 100% of the time. It is the programming equivalent of trying to walk a tightrope over a lake full of alligators while trying to avoid getting electrocuted by dangling power lines. The slightest mistake in your arithmetic at any one place in the code can be the difference between a perfectly safe program and remote code execution.
https://tonyarcieri.com/it-s-time-for-a-memory-safety-intervention
When will C fags learn?
>>
>>59628334
If you don't try to dereference it, it's not an issue.
>>
>>59628296
>I suggest that such cases are not rare.
Wrong.

>ugly wrapper
Or ugly wrapper around ASM like C people do
>>
>>59628331
I don't think there's ever been a C library for checking whether a value is zero.

https://www.npmjs.com/package/is-zero
>>
>>59628335
>dude php!
>>59628351
do you know what pointers are for?
>>
>>59628346
>I can't write safe C code, therefore nobody can
I'm sure there's a name for this fallacy.

>>59628357
>Or ugly wrapper around ASM like C people do
Hardly. C is portable, ASM is not.
>>
>>59628364
https://raw.githubusercontent.com/mohayonao/is-zero/master/lib/is-zero.js

>positive zero
>negative zero
is this a joke?
>>
File: 1442683815660.jpg (33KB, 600x586px) Image search: [Google]
1442683815660.jpg
33KB, 600x586px
>>59628364
>isPositiveZero
>isNegativeZero
>>
>>59628376
>Hardly.
Um, no not hardly. I see ASM being used in C projects very frequently, because C belongs to that niche
>>
File: 1486825755346.gif (2MB, 294x359px) Image search: [Google]
1486825755346.gif
2MB, 294x359px
>>59628376
C fags are delusional. Keep creating work for infosec. I hear Blackhat 2017 is going to have a all you can eat shrimp buffet
>tfw I'm a pentester and C fags are making me rich
>>
struct node {
void *data;
struct node *next;
};


So instead of writing a separate list container that holds a head pointer and the depth, just start with a node and use the next pointer to hold the depth value.
>>
>>59628396
source of that gif?
>>
>>59628378
>>59628382
>what is IEEE754
>>
File: dotCover.png (17KB, 928x271px) Image search: [Google]
dotCover.png
17KB, 928x271px
Anyone got experience with this retard dotCover? It's saying my code isn't properly tested but AreEqualIncludingHashCodes(null, null, true) and AreEqualIncludingHashCodes(null, null, false) should cover the whole null block
>>
>>59628275
Only if you're writing bare-metal software for a single-tasking machine.

>>59628282
>having your CPU nearly melt down from playing a 2D turn-based game is normal
Java apologists are awful.
>>
>>59628415
an abomination
>>
>>59628424
>your CPU nearly melt down
Poorfags BTFO
>>
>>59628415
Real talk here, where have you ever just sat down and thought to yourself "Well fuck I only wanted to execute that code on negative zero, not positive zero!"
>>
Reminder that C does polymorphism better than Go.
>>
>>59628430
Now that was edgy
>>
>>59628441
Well, Go has strings
>>
>>59628462
savage
>>
>>59628462
So does C.

typedef char* string;
>>
>>59628462
rekt
>>
>>59628441
Go has nothing going for it
it needs killed

>
import "fmt"

func main()
{
fmt.Println("Hello, 世界")
}


is invalid code.
>>
>>59628418
>public static void
Java?
>>
>>59628491
That's just sad.
>>
>>59628504
Nope. C strings are very efficient.
>>
>>59628500
C#, it's a class of test methods wrapping NUnit
>>
File: crying umaru.jpg (36KB, 600x337px) Image search: [Google]
crying umaru.jpg
36KB, 600x337px
Why do people make fun of me when they find out my whole program is written in C?
>>
>>59628516
Because it's C
>>
>>59628516
nice headers, nerd.
>>
First language: Haskell
Second language: Idris

What should I learn as my third language?
>>
>>59628516
Because they are not people.
>>
File: 1487405871275.gif (706KB, 1280x1086px) Image search: [Google]
1487405871275.gif
706KB, 1280x1086px
>>59628516
No one is making fun of you, they're just happy there's a larger attack surface for them when they want to steal people's baking info
>>
>>59628541
Patrician

Learn Cyclone or Rust
>>
>>59628400
There's literally no need for a "depth" value, especially if you'd need to traverse the list to the last element anyways. Just do

size_t depth(struct node *head) {
size_t n = 0;
struct node *a_node = head, *next_node = a_node->next;
if(a_node != NULL) {
while(next_node != NULL) {
a_node = next_node;
next_node = a_node->next;
n++;
}
}
return n;
}
>>
>>59628543
What if anon's software isn't going to use network?
>>
>>59628496
Why?
>>
>>59628565
http://www.cl.cam.ac.uk/~mgk25/pet2004-fpd.pdf
>>
>>59628496
>oh god my braces this is very very important how will i program now hepl me denis richie im being oppressed oh god ohgod oh god

>>59628510
Considering the number of string operations that require foreknowledge of the size of a string, no not really.
>>
>>59628549
>cyclone
>literally a proper C++
>now ded

wow
>>
>>59628434
My main computer is a laptop. I don't see any point in buying a super-powerful meme processor that couldn't run for more than five minutes without needing water cooling anyway. Besides, if a game isn't a 3D game from the last five years, it shouldn't be straining a modern processor. That's either a sign of bad programming, or using the wrong tool for the job.
>>
>>59628604
Good news is Cyclone lives in Rust
>>
>>59628543
I'd happily share my cookie recipe if they just asked, no need to hack me.
>>
>>59628579
python-tier parsing
>>59628601
muh freedoms
If i cant format like a human, then no thank you
>>
>>59628601
Well what even is the POINT of having braces if the compiler is going to sperg out about significant whitespace anyways?
>>
>>59628623
And rust is nothing like a proper c++
ripip
>>
>>59628633
Does that sequence contain a byte that would be " in ASCII?
>>
>>59628600
Well, that's not C issue now, it's electromagnetics issue now.
>>
>>59628600
How is this a C only problem?
>>
>>59628559
congrats you just turned measuring the size of the list into an O(n) operation
>>
So, guys, I have a question about solving a personal problem using programming.

I have a huge picture folder with probably thousands of pictures (at least hundreds) that are divided into subfolders.I place a new picture into a subfolder, and then create shortcuts for other relevant folders (that way I don't have dozens of copies of huge pictures uselessly eating up hard drive space). I recently moved my greater picture folder to a different hard drive. I'm sure that you can see the problem.

Going right click -> shortcut -> cut -> paste multiple times for every picture that goes in more than one folder would take hours. I figure that what I can do is create a list of every subfolder, and then have the program prompt where to move the picture to (if necessary) and where to place the shortcuts. Problem: I have zero knowledge on manipulating windows features specifically.

>Use this program!

Unless this would somehow take a ridiculous amount of work, it would be a good exercise to write it myself.
>>
>>59628754
So how would you do it, without having a separate field in at least one node?
>>
File: alt weight table.png (5KB, 352x84px) Image search: [Google]
alt weight table.png
5KB, 352x84px
This may be more of a math-related problem, but I figured I'd give it a try in /dpt/. I've been working on a performance calculator for large airplanes using some fuel-burn profiles I found online. The problem I am having is that in order to calculate total weight, you first need to know total fuel, which you can't calculate until you know the proper burn rate. Here is some pseudocode:

private int calculateOptimalAltitude(int grossWeight) {
....
// queries a table that returns an optimal altitude given a weight
return altitude;
}

private float calculateFuelBurn(int altitude, int grossWeight) {
....
// queries table shown in image to return the optimal fuel burn based on altitude/weight
return fuelBurn
}

private float getGrossWeight() {
return emptyWeight + payload + fuelLoad;
}



Can anyone point me in the right direction?
>>
>>59628806
just store the depth dumbass
increment when pushing a new node
>>
>>59628655
Whitespace isn't significant in the core language; statements are all terminated by semicolons. The compiler does a quick pass over source files to insert semicolons after certain tokens so programmers don't have to. This also has the not-unintended side effect of mandating a certain brace style, which the designers were fairly happy with.

If the braces were removed there'd be nothing to mark the ends of functions without redesigning and complicating the current grammar to have it pay attention to indents.
>>
>>59628788

Also, Java.

I was honestly never really interested in Java, but thanks to my comp sci classes (just started), this is the language that I'm the most fresh on.
>>
File: 1474792950875.png (145KB, 702x397px) Image search: [Google]
1474792950875.png
145KB, 702x397px
Which to learn is better, Sun-Oracle C# or Microsoft Java?
>>
>>59628754
It might get optimized out by the compiler anyway. Still shouldn't be retarded for the sake of simplicity.
>>
>>59628852
Haskell
>>
>>59628852
If I run Mono on my sparc64 machine, does it count as Sun/Oracle C#?
>>
>>59628822
As usual people in /dpt/ can't read.
>>
>>59628852
Common Lisp
>>
>>59628876
>It might get optimized out by the compiler anyway
No, it certainly wouldn't. That is way beyond what a modern compiler would do.
>>
>>59628876
Explain how a compiler is able to optimize away what is effectively a while loop of arbitrary length that may or may never halt.
>>
File: hammer_PNG3885.png (3MB, 2310x2543px) Image search: [Google]
hammer_PNG3885.png
3MB, 2310x2543px
What do i need to create a programming language with clear syntax and high performance?
Something simple and efficient.
>>
>>59628968
typed lambda calculus
consistency
>>
how do i become programmer god and write hundred thousand lines of code a day?
>>
>>59628968
Just recreate C, but faff around with the syntax a bit.
>>
>>59628968
How much performance is high for you?
What kind of syntax is clear for you?
What's complicated for you?

AND NEVER BRING MEANINGFUL WHITESPACE
>>
>>59628968
you don't need to do that, just use C
>>
>>59628968
>>59628986
Lisp
>>
>>59628986
>More lines of code is better
Spoken like a true programming nooblet.
>>
If I need to count down an int every 100Hz how do I accomplish this?
>>
>>59628986

How many lines of code a day do you write now?
>>
>>59629020
>every 100Hz
You could have just said 100 times a second.
Just use whatever high-precision clock/timer that your language provides.
>>
>>59629034
2.555k and then my brain is so fucking tired i can't do anything for the rest of the day
>>
>>59628986
#include \
<studio.h>

int
main
(void)
{
printf
("H\
e\
l\
l\
o\
,\
w\
o\
r\
l\
d\
!\n");
return
0;
}
>>
>>59629013
He said clear syntax
>>
>>59629061
>studio.h
This is some next-level shitposting.
>>
>>59629050

Have you tried Adderall?
>>
what do you think of lbry.io, /dpt/?
>>
>>59629093
I have yet to meet an .io I haven't hated.
>>
>>59628986
Get a million dollars, build a massive GPU cluster, and run an LSTM NN on github/answers to those coding question websites for a month. Then just have it apply to companies as you.
>>
>>59628986
#!/bin/sh
# metaprogram
echo '#!/bin/sh' >program
for I in $(seq 99999)
do
echo "echo $I" >> program
done
chmod +x program
>>
>>59629075
It's illegal here
>>
File: languages3.png (17KB, 522x384px) Image search: [Google]
languages3.png
17KB, 522x384px
People will still disagree with this image, incredibly.
>>
>>59629261
I disagree with it because libraries exist. Python/Ruby are great for glueing shit together when performance isn't required. Like near-zero dev time.

Go... not so much.
>>
>>59629261
I don't
>>
>>59629003
High performance the obvious c++/D
Clear syntax i like Python's but hate the white space bullshit.
In resume i want to make a lang that allows you to use all your tools without having to deal with a convoluted clusterfuck of code.
I know that this is nearly impossible with advanced knowledge but a man can dream.
>>
>>59629304
D is not high performance.
>>
>>59629304
Without*
FUCK
>>
>>59628788
>it would be a good exercise to write it myself.
Sure, go for it. Dive deep into msdn and windows functions, shell links for instance. Might be your first github record of a neat little project. I am not sure about Java tho in this case. C#/C++ ought to be more suitable.
>>
>>59628788
That can be done in shell scripting or batch.
>>
>>59629261
Because Python is much faster to develop in than in haskal or other FP meme languages.
>>
>>59629261
Python is great for prototyping shit with a team, literally Pseudocode: The Language. Not everyone likes reading ((((lisp)))) or haskell

that's how things worked at my last place
>throw some shit in python
>the concept kinda works
>rewrite everything carefully using our c++ libs
>>
>>59629392
This. Python is great for prototyping.
>>
>>59629392
>>59629390
Python's lack of support for decent FP is absolutely crippling. I can prototype stuff quickly in Scala (with scalaz) or Haskell, no problem. All the high-level functions are there at my fingertips, ready to use. Python just doesn't have them.
>>
>>59629319
Yes it is
>>59628302
>>
>>59629470
>comparing it against go and scala
"high performance"
>>
>>59629489
>I didn't actually look at the benchmarks
>>
>>59629433
Yeah, I can see the appeal but as I said
>implying your teammates can into any fp

hell, everyone freaked out when one guy wrote a neat prototype in smalltalk and the other time our lisp guru tried to show his work
>>
File: 1479322475155.png (2MB, 1280x1717px) Image search: [Google]
1479322475155.png
2MB, 1280x1717px
What's the most widespread scripting language?
No Javascript.
>>
>>59629541
Probably perl legacy. It isn't the most commonly used by a lot today but it's the most commonly installed for the past 30 years.
>>
>>59629392
hold on a sec
so lisp is a jew language?!

>look up
>McCarthy was born ... to an Irish immigrant father and a Lithuanian Jewish immigrant mother
>>
>>59629541
English
>>
>>59628275
Unless you are initializing a pointer to NULL, no.
>>
>>59629525
My coworkers were like that at first, but they went away and learned more FP because they needed to be able to understand my code.
>>
>>59629541
Py
>>
>>59629541
ancient Perl code or Python.

>>59629548
It's fucking great to learn and have on your resume, huge boost on the job market at bigger companies.
>>
>>59628817
So if I'm understanding you correctly, what you need is
>Total Weight to get Altitude
>Total Fuel to get Total Weight
>Burn Rate to get Total Fuel
>Total Weight to get Burn Rate

This is cyclic, so there's no way to do this (at least to my limited knowledge)... Are you sure there's not another way to calculate weight? Can't you estimate?

Also, are you sure you need total weight for the fuel burn and not just the plane's weight? Because the weights on the table look like they might just be the weight of the plane.... But you probably know more about this than I do
>>
>>59629580
Yes, knowing perl will help them hold together their shitty infrastructure for another decade. Do you really want to live that life though?
>>
>>59629580
For real? I am always so scared trying to read perl
>>
>>59629606
Companies using technologies like perl and python should be left to fail.
>>
>>59629611
>>59629622
It is a thousand times easier to write it over than to read what's been written. This is the perl lyfe.
>>
>be programming
>debug messages everywhere
>all is well
>remove debug messages
>shit breaks completely
This has to be the most infuriating thing in programming.
>>
>>59629553
so the jews were behind the parentheses meme all along?
>>
>>59628491
Not a string or an argument.
>>
>>59629664
A string is LITERALLY just a linear sequential container for characters.
>>
What is a good, interesting, platform to mess around with assembly on?

I've been considering NES, but wondered if anyone else had some suggestions.
>>
>>59629692
Okay, what defines a character? Hint, it's not memory size.
>>
>>59629711
MIPS
>>
>>59629720
I said interesting.
>>
>>59629711
x86_64 is pretty interesting
>>
>>59629720
>>59629711
The classics are fun to play on, 6802/Z80. Easily emulated. Then you have like arm cortex maybe/mips that are less fun but practical. Big CISC shit is not fun.
>>
>>59629717
>what defines a character?
That's quite a broad philosophical question
>>
>>59629745
I was looking at older machines where it actually makes sense to use assembly.
>>
Is there a name for this data type?
The best i can think of is "rolling list".
I want a buffer of X elements. As i add eles the oldest ones get replaced.
And i dont simply want an array that shuffles the old data to the end and puts the new in the front.
>>
>>59629711
SNES
I was considering on doing a basic calculator but i'm barely learning asm.
>>
File: 1481134256740.gif (885KB, 250x250px) Image search: [Google]
1481134256740.gif
885KB, 250x250px
Is it true that you can write some Java 8 code and it is going to work in old versions?
>>
>>59629769
Circular buffer
>>
http://www.strawpoll.me/12629785
>>
>>59629831
>cracking the coding interview
lol no just learn algos.
>>
>>59629831
both
>>
>>59629831
I wonder if anyone actually read clrs to the end
>>
>>59629826
Thanks
>>
>>59629711
8086
>>
>>59629711
c64 is neat
>>
>>59629831
>cracking the coding interview
You srs bro?
>>
>>59629831
Learn to program, not just how to fake it in an interview.
>>
>>59628346
tonyarcieri is a SJW
>>
>>59628346
C is high testosterone (pic related)
>>
>>59629711
Probably something 6502 based, or from that era. Most non-embedded systems stuff these days uses x86/x86-64, but it's really intended as a compiler target rather than something for humans to use, so it's not really a good choice for learning asm.
>>
>>59628346
guess he's the victim of C natural selection lel
>>
File: 1fe.png (37KB, 658x662px) Image search: [Google]
1fe.png
37KB, 658x662px
I'm pretty new to programming, and I don't understand what call-by-reference parameters are. Can someone please explain? Is it something only used for recording input, and if so, how useful is it?
>>
>>59630085
dumb frogposter
>>
>>59630104
Yes, I am. Please help me understand.
>>
>>59628212
C/C++/Rust:
> write naive program that uses malloc and is slow
> optimize to avoid allocations, use pool allocation etc, program gets fast


Lisp/Haskell/etc
> write naive program that uses lots of allocations and is slow
> optimize to avoid allocations, use pool allocation etc, program gets fast
>>
>>59630104
that just makes him slightly smarter than you
>>59630085
when you pass by reference, the variables you used to call the function change, because instead of giving the data to the function, you're giving the address of the variables that you call the function with, directly modifying the value in the caller function variables.
>>
>>59630085
look up the difference between pointers and references.
>>
>>59630085
What it is: just google it.

Why use it: either because you want a function to have multiple "returns" (pass multiple parameters by reference and the function can change them all) or because the function needs to actively change the data in order to fully use it and copying a duplicate would be excessive/unnecessary because the data will be as it found it in the end (usually in a data buffer type situation).
>>
>>59628171
Newfag here, getting used to c++ by doing euler project shit. https://projecteuler.net/archives
Any anons know better ways to practice?
>>
>>59630085
>>59630111
well in call by reference, you're passing the memory location to the parameter. so i'd assume you're able to actually change the thing in memory. normally if you pass a parameter to a function, it gets a copy. not the real thing
>>
>>59630171
...write something useful instead?
>>
>>59630085
How much you wanna know/do you know? Passing values by reference is almost always a good idea for large objects. Consider a huge picture you want to modify. It's considerably quicker/more space efficient to pass a reference to a single picture in memory around, then continuously copy new pictures for each function call. If you already knew that, it's really just conceptually syntactic sugar for passing a pointer to an "object". Note in this case the object itself can be a pointer.
>>
File: dpt-poster.jpg (517KB, 1521x1076px) Image search: [Google]
dpt-poster.jpg
517KB, 1521x1076px
>>
>>59630171
Make a calculator with GUI
>>
Have some shit file reading program project in C.
Is it better or doesn't really fucking matter to:

a) read lineRead, convert, store in array, keep count, allocate memory for new array, populate new array

b)readLine, keep count, allocate memory based on size for new array, read from the beginning and store into new array

The new arrays will be manipulated later in the program.
>>
File: howdointocode.png (37KB, 1127x685px) Image search: [Google]
howdointocode.png
37KB, 1127x685px
>>59630184
Good idea, but actual projects are very big and I am very shit.
>>
>>59628212
If you are using smart pointers without Garbage Collector then you're still doing all the work of a Garbage Collector and using all the memory of a Garbage Collector only without the possibility of deferring collection to a time when processor-usage is low or at the very least not in the middle of a time/sensitive method like when you have control of the graphics context. While it helps to make the code more modular (there's a reason no one writes DLLs in Java), in large programs it's really a performance loss.
>>
>>59630222
Make something simple thing.
For a start how about making a script that scrapes all of 4chan and saves all images with pepe inside.
>>
Is there a portable solution to SEEK_END not being "required"?
>>
>>59630218
>Have some shit file reading program project in C.
have some respect when talking about C mate. also your question's not really clear. you're trying to put things from the input into an array? go through once to find the size, and then go through again after making the array. be aware sometimes variable sized arrays cause problems, i think it's C99 and later it'll work
>>
>>59630222
stop posting frogs
>>
>>59630250
>with pepe inside
That's almost impossible
>>
>>59628212
Will we eventually reach a point where performance is fast / desired no matter how shit the underlying design?
>>
>>59630289
Basically I was asking whether or not to store in a fixed sized array on the first read and then take it from that that to store into an dynamically sized array.

Or just to get the size only on the first read, creat the new array, then read the file again to populate the new array.
>>
File: 1481125861005.jpg.jpg (56KB, 636x446px) Image search: [Google]
1481125861005.jpg.jpg
56KB, 636x446px
I'm working on learning OpenGL.

It's really an incredible pain in the ass.
>>
>>59629553
This makes me nervous because I used to think /pol/ was joking until they invaded other boards. Please tell me that you are blaming stuff on the jews ironically.
>>
>>59630218
prob something like:
char buffer[MAX_SIZE]
char ** lines;
while(fgets(buffer, MAX_SIZE, file_pointer) != NULL) {
// Allocate a new char * for the current line, append to lines
}
//Go off and read through our gathered lines, but make sure to free them when we are finished.

Note you wouldn't have to do any allocations if you could process each line within the while loop.
>>
>>59629635
use a debugger, nerd
>>
>>59630361
learn vulkan lad
its so much better.
>>
>>59630349
You don't need a 100% rate with image recognition. You are allowed to have false positive and false negatives. This teaches you the basics of building a database (of pepes) and how to use image recognition tools and computer vision. Or if you are really fucking lazy, you can just use the multiple image search engines available on the web (google, iqdb etc) to run your images through. Just remember to set a wait time least you get flagged for DDoS.
>>
exit interview today!
>>
>>59628272
post video
>>
Doing transistor layout. I want to kill myself, tbqh.
>>
>>59628620
>what is dwarf fortress
>>
>>59630449
Congrats. Now you can be a NEET too.
>>
>>59628335
>1 bit = 8 bytes
Swell.
>>
File: 1467663665086.png (1MB, 1280x720px) Image search: [Google]
1467663665086.png
1MB, 1280x720px
>>59630449
good luck!
>>
>>59630361
>incredible pain in the ass
why though?
I think it's bretty fun
>>
>>59630485
Not written in Java.
>>
>>59628171
Working on CSS on a friend's website for a quick buck
>"Youare a programmer dude, fix my css dude"

Jesus fuck, how do webdevs keep it together and not kill themselves
>>
>>59630394
I would, but it's time-sensitive code so it works just fine in a debugger.
>>
>>59630582
>why don't webdevs..kill themselves?
fixed
>>
File: gfs_62784_1_6.jpg (49KB, 1000x583px) Image search: [Google]
gfs_62784_1_6.jpg
49KB, 1000x583px
What lisp dialect should i learn?
I'm a hobbyist.
>>
>>59630610
ocaml
>>
>>59630610
liskell
>>
>>59628346
Ctards BTFO
>>
>>59630610
Common Lisp
>>
Have you ever contributed to oss /dpt/? I am too shy to pull request tbqh, people will bully me
>>
>>59630733
yes. start off with small bug fixes before doing features
>>
>>59630722
Is it better than scheme?
>>
>>59630733
i personally have made changes to some stuff but cant be fucked formatting it to spec and going though a commit appeal.
>>
>>59628171
Is there a GCC option that warns you about uninitialized variables in loops? I somehow managed to write the following:
for(int i, j = 0; i < hexStrLen; i+=2, ++j){...}


Compiling with "-Wall -Wextra -Wuninitialized -Wmaybe-uninitialized" does nothing.
>>
>>59630772
Time to use a different language
>>
>>59630787
It was for a uni project.
>>
>>59630753
Yes, it's more batteries-included than Scheme and has many libraries.
>>
>>59630772
try -Weverything
>>
>>59630772
-pedantic-errors
might catch it
>>
>>59628378
>"use stirct";
>>
>>59630795
>clang
>>
>>59630814
nope
>>
>>59630830
oh

use clang then
>>
>>59630850
try
-Weffc++
>>
>>59630401
I'm strongly considering switching to vulkan the next time I get some free time. I hear it's lower to the metal. Is it simpler because of that?
>>
>>59630876
oh wait
-Winit-self
>>
>>59630853
Holly shit. Ran it just to leave a snarky post, but it manage to discover not only that issue, but several others. Also the original issue was discovered by -Wuninitialized. Why is GCC so shit, and why is it being shilled so much?

Capcha: Toilet MECHANIC
>>
>>59630876
It's C.
>>59630892
Nope.
>>
>>59630891
>Is it simpler because of that?
Technically no, theres more steps with the added control, but the API in general is so much more pleasant to work with so you dont really notice.
>>
>>59630904
GCC is ancient and the old people have enough experience with it to know these things.
>>
File: common_lisp_is.png (64KB, 879x412px) Image search: [Google]
common_lisp_is.png
64KB, 879x412px
>>59630722
>>
what level do you have to be at to get an entry-level programming job? I read a book on Java and did all the exercises, yet I feel like the most I'm currently capable of is building a simple calculator, and that's only if I get some help from Googling a bunch of shit.

what kind of projects do employers want to see? how complex do they have to be?
>>
File: 1382067989970.jpg (1MB, 3000x1688px) Image search: [Google]
1382067989970.jpg
1MB, 3000x1688px
>>59630904
>Why is GCC so shit, and why is it being shilled so much?
freedom ain't free unless its littered with blood of GNUs
>>
>>59630949
If you gauge a language's worth by its popularity, you should just use Java.
>>
>>59630945
I know perfectly well that "int i, j = 0" will leave i uninitialized. It was a typo or a brainfart or whatever you want to call it. Shit happens, and seeing how there is a "-Wuninitialized" option provided, it would make sense for it to actually do what it claims to do.
>>
>>59630904
You tell me. I cringe every time I see stallman's stupid face in the sticky.
>>
Books to learn modern C++ as a beginner?
>>
>>59631097
Don't.
>>
#include <stdio.h>
#define MAXLINE 1000

int mygetline(char line[], int maxline);

/* print longest input line */
int main(){
int len; // current line length
char line[MAXLINE]; // current input line
int target = 80;
int i, j;

while((len = mygetline(line, MAXLINE)) > 0){
if(len != 1){
for(i = len; i >= 0 && (i == ' ' || i == '\t' || i == '\n'); --i);
for(j = 0; j < i; j++) putchar(line[j]);
}
}
return 0;
}

// read a line into s and return the length
int mygetline(char s[], int lim){
int c, i;

for(i = 0; i < lim - 1 && (c = getchar()) != EOF && c != '\n'; ++i){
s[i] = c;
}
if(c=='\n'){
s[i]=c;
++i;
}
s[i]='\0';
return i;
}


when i run cat 1-18.c | ./1-18 > output.txt, it doesn't remove the spaces i put after return i;. anyone know what i'm doing wrong? i put in 5 spaces and they're all still there. the empty lines are removed but that's all
>>
>>59631121
So what do I learn then? Don't bother mentioning C
>>
How often do you use threads in csharp programming? what type of tasks do you use them for? Do they really make a difference?
>>
>>59631128
and ignore the comment for main, copy and pasted from a previous exercise. its purpose is to remove whitespace at the end
>>
>>59631097
Not sure that exists to be fair. Maybe use Stroustrup's book.
>>
>>59630610

Write your own, there are heaps of tutorials
>>
>>59631129
nigger
>>
>>59631159
Fuck off, idiot
>>
>>59631129
C
>>
>>59631174
fuck off nigger
>>
>>59631129
C==
>>
>>59631128
>(i == ' ' || i == '\t' || i == '\n')
Here you're comparing the index to a character, not the character itself.
It should be line[i] == ' ' and so on.
>>
>>59631128
write line[i] to stderr. Is line[len] a null character?
>>
>a 1 hour talk about how cpu cycle-level optimization is important it their field

>some mong comes up and basically says speed isnt important as long as it works

What is it about conventions that bring out just the absolute worst autists?
>>
>>59631188
>>59631194
I know C you fucking autistic trash just fuck out of my face
>>
>>59631203
ah thanks, i'm a bit tired. 11:27pm where i'm at
>>
>>59631208
Python users, man
>>
>>59631129
Learn html, css, and javascript. Watch derke banas "learn in one video" for all three, and go through w3schools' lessons.

It easy to play around and try stuff, and all you need is a regular text editor and you can test your program in a browser
>>
>>59631228
Oddly enough it was a c++ con talk.
>>
>>59631208
Cache utilization >>>>> cycle optimization. Modern day OoO speculative CMPs can process so fast it's rarely a problem with # of cycles spent in act. calculation.
>>
What was the rationale behind putting all the C memory manipulation functions in string.h?
C doesn't officially have strings, why didn't they just call it memory.h?
>>
>>59631206
>>59631203
both of these were part of it, this works now
#include <stdio.h>
#define MAXLINE 1000

int mygetline(char line[], int maxline);

int main(){
int len; // current line length
char line[MAXLINE]; // current input line
int target = 80;
int i, j;

while((len = mygetline(line, MAXLINE)) > 0){
if(len != 1){
for(i = len-1; i >= 0 && (line[i] == ' ' || line[i] == '\t' || line[i] == '\n'); --i);
for(j = 0; j <= i; j++) putchar(line[j]);
putchar('\n');
}
}
return 0;
}

// read a line into s and return the length
int mygetline(char s[], int lim){
int c, i;

for(i = 0; i < lim - 1 && (c = getchar()) != EOF && c != '\n'; ++i){
s[i] = c;
}
if(c=='\n'){
s[i]=c;
++i;
}
s[i]='\0';
return i;
}


thanks
>>
>>59631309
>C doesn't officially have strings
(You)
>>
>>59631325
It doesn't
>>
>>59631155
that sounds pretty fucking hard pal.
>>
>>59631340
http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1570.pdf
I'm seeing "string" mentioned quite a few times.
>>
>>59631358
Uh?
string str = "trash"; doesn't seem to compile
>>
>>59631372
>>59631358
what provides it?
>>
>>59631372
>In order to have strings, you must have a type explicitly called "string"
I guess none of the dynamic-shitter languages have strings either.
>>
>>59631384
> typeof("foo")
"string"
>>
>>59628968
llvm
>>
>>59631384
>in order to have strings, you must have a typedef every single time and pretend C has strings
I guess C shouldn't have chars either
>>
>>59631309
It's pointless to even form opinions on these kinds of things because they are decades old and they aren't changing any time soon
>>
File: 1485085748973.png (132KB, 1920x1040px) Image search: [Google]
1485085748973.png
132KB, 1920x1040px
>Because the only thing on nuget that seems to do what I want fails to close the file in a using block + doesn't periodic save.
>>
>>59631384
>"dynamically typed languages don't have types"
stop

C has strings insofar as string literal syntax, plus somewhat nasty rules about how to allocate these strings. I'd say that yes C does have strings, they just fucking suck.
>>
File: 1453302491365.png (129KB, 314x278px) Image search: [Google]
1453302491365.png
129KB, 314x278px
>>59631403
$ cat test.c 
#include <stdio.h>

#define typeof(v) _Generic((v), \
char *: "string" \
)

int main()
{
puts(typeof("foo"));
}
$ gcc test.c
$ ./a.out
string
>>
>>59631430
That is a fair assessment, unless you're talking UTF8 or something.
>>
>>59631430
>stop
You seem to have missed my extremely stupid point.
>somewhat nasty rules about how to allocate these strings
It's the same way you allocate anything else.
>>
>>59631443
>#define typeof(v) _Generic((v), \
> char *: "string" \
>)
Now that's just sad
>>
>>59631446
Does C have a reliable and widely used UTF-8 library yet? Do C programmers still think ASCII is sufficient?
>>
>>59631443
>Before C11
>"HURR DURR WE DON'T NEED GENERICS :DDD"
>>
>>59631472
>It's the same way you allocate anything else
no
const char* str = "hello";
char str[] = "hello";
>>
>>59631480
Just use libiconv if you need to deal with encoding shit.
However, a lot of C programs just ignore UTF-8 and just pass it though unaltered.
>>
>>59631496
>const char* str = "hello";
Yes, this is a pointer to some unnamed statically allocated memory.
I suppose you're skipping a step, but it's no different than
static const int[] __unnamed = {1, 2, 3};
int *ptr = (int *)__unnamed;

>char str[] = "hello";
This is just some syntactic sugar for an array declaration.
>>
>>59631474
>>59631487
But the "typeof" returns "string", so it must be a string?!
>>
>>59631570
Yeah, you had to implement your version of strings, people probably already have done something useful by that time.
>>
Hi\0 guys\0
Does\0 C\0 have\0 strings?\0
>>
>>59631609
>Hi\0
sup anon, what is your question?
>>
File: wznBM.png (44KB, 575x472px) Image search: [Google]
wznBM.png
44KB, 575x472px
>>59631625
Does\0 C\0 have\0 strings?\0
>>
Can I use Python without __this__shit__? I know it's part of the OFFISHUL style and all but I just hate it. It looks tacky af and my autistic brain can't handle it. I love Python, but I just wish I didn't have to see that. It's why I weirdly wish Swift wasn't just an Apple garbage language.
>>
>>59631637
>Does\0
does what? i think your sentence got cut off
>>
>>59631645
If this minor of a detail stops you from being productive, then the real problem might just be you being a bad programmer
>>
>>59631652
Well\0 I\0 guess\0 it's\0 not\0 possible\0 to\0 read\0 more\0 than\0 one\0 word\0 in\0 C\0
>>
>>59631609
Yes.
A string in C is defined as a char array with a terminating null byte.
>>
File: SpaceCadet2.jpg (94KB, 1023x527px) Image search: [Google]
SpaceCadet2.jpg
94KB, 1023x527px
>>
>>59631677
I'm very productive usually, I just have this autistic hangup about Python with this. I've been looking around for a nice general purpose language for prototyping bullshit (I tried node.js and found it fun af to fuck around with... but then I realized javascript is slow garbage with lots of pitfalls) and Python is conceptually good. I might just meme and go with Rust though at this point.
>>
File: r-badge.png (75KB, 220x220px) Image search: [Google]
r-badge.png
75KB, 220x220px
>>59631696
>>
Why do people still feel the need to write needlessly obfuscated code?
Compare the code in the image with the thing below. I'm honestly curious, would anyone prefer the one in the image over the one below?
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int left, int mid, int right)
{
std::cout << left << "\t" << mid << "\t" << right <<std::endl;
int firstArrInd, secondArrInd, mergedInd;
int n1 = mid - left + 1;
int n2 = right - mid;

/* create temp arrays */
int L[n1], R[n2];
/* Copy data to temp arrays L[] and R[] */
for (firstArrInd = 0; firstArrInd < n1; firstArrInd++)
L[firstArrInd] = arr[left + firstArrInd];
for (secondArrInd = 0; secondArrInd < n2; secondArrInd++)
R[secondArrInd] = arr[mid + 1+ secondArrInd];
/* Merge the temp arrays back into arr[left..r]*/
firstArrInd = 0; // Initial index of first subarray, keeps track of the next-smallest integer
secondArrInd = 0; // Initial index of second subarray, keeps track of the next-smallest integer in the right subarray
mergedInd = left; // Initial index of merged subarray
while (firstArrInd < n1 && secondArrInd < n2)
{
if (L[firstArrInd] <= R[secondArrInd]) //if the second array's index at an index is greater
{
arr[mergedInd] = L[firstArrInd];
firstArrInd++;
}
else // if(L[i] > R[j])
{
arr[mergedInd] = R[secondArrInd];
secondArrInd++;
}
mergedInd++;
}
/* Copy the remaining elements of L[], if there
are any */
while (firstArrInd < n1)
{
arr[mergedInd] = L[firstArrInd];
firstArrInd++;
mergedInd++;
}
/* Copy the remaining elements of R[], if there
are any */
while (secondArrInd < n2)
{
arr[mergedInd] = R[secondArrInd];
secondArrInd++;
mergedInd++;
}
}
>>
>>59631686
That\0 doesn't\0 look\0 like\0 a\0 string\0 to\0 me\0
>>
>>59631708
I like R when I'm doing regressions... that's about it.
>>
>>59631718
>obfuscated code
If you write C, C++, Rust or Java the code is automatically obfuscated. Not even kidding
>>
>>59631696
>wants to prototype
>"slow garbage"
You sound misinformed. Although node.js is still bad.
Rust is terrible for prototyping. Writing Rust code is always a struggle. People who have never written C/C++ code and think that Rust is going to be a walk in the park are just bandwagon idiots.
Python is fine for prototyping especially for the web. It depends what you're doing.
>>
>>59631718
The code in the image is much easier to understand because you don't have to keep scanning horizontally to see it all.

Also both those examples are needlessly complex.
>>
>>59631696
no, python needs to have that stuff because it is an autistic language
>I've been looking around for ...
you could perhaps try lua
>>
>>59631718
The problem is that you have awkward loops everywhere that don't explain themselves very well. You have to rely on comments in order for anything to make sense without really thinking about it.
To solve this you just need more general abstractions, and then your main algorithm will be smaller code that just calls a few routines, and is easier to digest than scrolling through comments or looking at ugly variable names
>>
Help I'm too stupid for C

Can you write me a function that can add two values?
>>
>>59631214
stop pretending you know C, twat
>>
what's C
>>
>>59631214
no you don't
>>
>>59631840
I bet you can't even average 2 numbers in C
>>
>>59631840
>>59631853
Fuck off samefag
>>
In C++, while doing an if statement, how can I ask IF an int is one of several numbers?

Ex.)

if (int = (1, 2, 3, 6, 7))
then ... etc.

I'm a programming newfag and I can't figure this out.
>>
>>59631834
Bump
>>
>>59631877
int i = ...;
if (i == 1 || i == 2 || ...)
>>
NEW THREAD

>>59631903
>>59631903
>>59631903
>>
>>59631834
int add(int x, int y) {
return x+y;
}
>>
>>59631696
if you're used to not having to deal with safety literally everywhere, you're probably not going to enjoy moving from python to rust.

>>59631745
indeed.
https://ghostbin.com/paste/krktw
>>
>>59631884
Ah, yes I was thinking something like that but my in name is actually a Class.Function() so it's going to get ugly. Was hoping there was a cleaner way but this will have to do. That's the symbol for "OR" correct?
>>
>>59631834
unsigned int myAdd(unsigned int a, unsigned int b)
{
unsigned int carry = a & b;
unsigned int result = a ^ b;
while(carry != 0)
{
unsigned int shiftedcarry = carry << 1;
carry = result & shiftedcarry;
result ^= shiftedcarry;
}
return result;
}
>>
>>59631920
Yes, thats "OR"
If you have a fuck ton of values you might want to put it into an array and search there.
>>
>>59631932
Good suggestion but I don't have too firm of a grasp on arrays yet.
>>
>>59631904
Why do you guys push for new threads so early? Do you not understand how the board operates?
>>
>>59631908
>>59631928
>>59631965
>>
>>59631976
bump limit friendo, get with it
>>
>>59632009
Yeah but there's pages to go, this thread will be here another 30-60 minutes.
>>
>>59632042
life is short,FUCK the other pages
>>
>>59631372
Yeah that doesn't compile in sepples or java either.
>>
>>59631679
>thinking nul is the same as a space
Thread posts: 334
Thread images: 30


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.