Old thread: What are you working on, Sup Forums?
/dpt/ - Daily Programming Thread
Other urls found in this thread:
github.com
github.com
youtube.com
steve-yegge.blogspot.com
youtube.com
youtube.com
dotnetfiddle.net
twitter.com
From a performance point of view, is it worth using functional concepts in C++ for performance critical applications (such as gaymes) ?
I'm not only talking about map/reduce, but also writing pure functions, and immutable lists.
It makes me believe it involves a ton of heap usage that's a huge bottleneck in applications.
Am I right?
FUCK YOU FAGGOT
I'm working on trying to sleep, and getting depressed once again
Please do not post an anime image next time, thank you.
Haskelling the rewrite linux in kernel
I want to sniff Himegotos hair
There are other data structures besides arrays and lists. Sets, stacks, queues, heaps, trees, etc. That's more what I meant.
No you aren't right because the majority of code isn't performance critical. Only a small percentage of lines are. Also
>using C++'s awful FP concepts
Have fun praying to the auto gods while typing more letters in {!@#$%^&*()} than alphanumeric ones.
Hey guys! Thanks for all the help. Here's the solution for averaging two ints in C properly, according to my professor, in case anyone missed it from the last thread:
#include
#include
#include
#define JAVACODE "public class Average {\n
public static void main(String[] args) {\n
int a = Integer.parseInt(args[0]);\n
int b = Integer.parseInt(args[1]);\n
int c = (a + b)/2;\n
System.exit(c);\n
}\n
}"
#define JAVA_CMDLINE "java Average %d %d"
int main(void) {
FILE *fp = fopen("Average.java", "w+");
if(NULL == fp) {
return -1;
}
size_t javacode_len = strlen(JAVACODE);
fwrite(JAVACODE, javacode_len, 1, fp);
if(ferror(fp)) {
return -1;
}
fclose(fp);
system("javac Average.java");
puts("Please provide two integers to average, separated by a newline:");
int a, b;
scanf("%d", &a);
scanf("%d", &b);
size_t buf_size = strlen(JAVA_CMDLINE) + 1 - 2;
char buf[buf_size];
sprintf(buf, JAVA_CMDLINE, a, b);
char const *aux = buf;
int c = system(aux);
printf("Result of averaging %d and %d: %d\n", a, b, c);
return 0;
}
Function purity and immutability are nice to have, they can reduce the risk of some types of bugs, and sometimes they can help the compiler make optimizations that would otherwise be impossible.
But if performance is your absolute highest priority, sometimes in-place algorithms are necessary, and that calls for mutability.
Is this bait?
kek
>Functional ....
This is a canned response. It isn't even addressing what he asked, which was about mixing paradigms.
Should I use this book to learn C?
>Only a small percentage of lines are.
Are you implying performance isn't about the general program structure ?
>they can help the compiler make optimizations that would otherwise be impossible.
The problem with that is that the compiler isn't allowed to make the same assumption in C++ than in Haskell or others pure functional languages.
Is reading Tannenbaum the recommended way to learn generally about networks or are there better resources?
Nah, it was very much geared toward the decision of whether to use FP concepts in C++. Although the same type of reasoning does also apply when comparing languages. I've seen C and C++ programmers decide that non-const arguments are "evil," and that certainly does have a performance cost.
>Is this bait?
nope, professor sent me it
Would you guys reccomend the Python course of Codecademy for an absolute beginner?
I started recently and sometimes I have trouble understanding what they ask me to do.
>non-const arguments are evil
Maybe if C had the ability to do multiple returns that would be more legitimate.
Not to mention returning pointers to structures rather than pre-allocating them and modifying is both worse performance-wise and software glitches-wise. Memory leaks are the second most insidious kind of bugs. Stack > Heap.
I'm assuming that the general structure is ok.
I'm not accusing you of baiting, I'm accusing your professor. This was like when my Intro to Unix professor made the Unix-Hater's Handbook a required textbook, then assigned us to set up Xfree86 (not Xorg) and manually calculate our monitor timings. This was in like 2010 too.
I agree with you, you shouldn't let functional programming religion get in the way of writing good code. Sorry, I should have been more clear, that was the point I was trying to make.
>I'm assuming that the general structure is ok.
No, I mean, a C++ program written using FP concepts can and will have a different structure than your average program, what I'm asking is, does it involves a performance penalty ? Because to me, it'd make a lot of calls to new to allocate lists, passing lambdas around, and also possibly involve meta-programming abuses.
(No, I'm not talking about making a program using only the functional paradigm in C++, but just having the general structure of it).
Not sure if I'm clear.
What I was trying to say in my initial comment (and again, I apologize if I was unclear) is that sometimes FP concepts can help performance. In which case, feel free to use them. But if performance is your goal, you shouldn't forgo a good optimization just because it violates purity, or whatever.
What is the point of C# auto implemented properties if you can't alter the getter and setters? How is it any different than just using a field?
You don't apply wholesale FP conversion to your program, just the bits where FP is most useful. For example, in renderengine.c you use the fastest code and elsewhere use FP when it's nice.
And yes performance is determined by a very small part of bottlenecking code.
The excuse I've heard is that it's standard and the OOP way (TM). Alternatively I've heard that "libraries expect functions rather than fields."
What a dumb reason. Especially considering typing 'propfull' and two tabs basically gives you the same thing with a lot more flexibility. Reading some SO threads seems to solidify that point.
I just saw a youtube video were a guy made a ray tracer in c that compiled with TCC in milliseconds and stored the state of the program in non-volatile memory so he could modify his game while it was running
pretty cool shit, someone should make a compiler optimized for this
>does it involves a performance penalty ?
think about it. calling functions that call functions that call functions... that's exactly what wastes time and resources in C/C++
wait shit you can do this on android? link for how to isntall?
You can do this in volatile memory. You simply have to set the pages of executable memory to be writeable. But to make useful changes, yeah the compiler has to have some changes.
I know exactly what video you're talking about.
It was pretty impressive, and I hoping to write something comparable using LLVM, one day.
search for OCaml Toplevel for Android on the play store
>last updated 2011
hm, this could be a fun project to update/rebuild. looks like it'd be possible to port the whole compiler by just cross-compiling and adding this patch: github.com
there are even some packages for android on OPAM already: github.com
Is there no way to find the creation time of a file using stat in C? I've only been able to find the last access and modification times. Nothing on creation.
Post video.
Stat in the command line has blank entries for birth for some reason on my system.
That depends on the filesystem you are using, some store that information while others don't
youtube.com
You're lucky I found something that old that fast.
Interesting, thanks guys.
You can still specify the accessibility of the getter and setter. And C# is built on the principle of separation of implementation and interface. Generally (with the exception of trivial structs), raw fields are for implementation and should be private, while public interface should be properties and methods. This is makes more sense in C# than say C++, since all class instances are passed by reference and there is no const qualifier.
cause of "muh encapsulation" bullshit
I have no idea what he's talking about, but that video is trippy as fuck
The point is to make it difficult to use a class incorrectly. When everything passes by reference and without a const qualifier, a public field is dangerous. Properties at the very least qualify getter/setter presence/accessibility, and can otherwise sanitize input, apply dirty-flag behavior, etc. It's basically just syntactic sugar replacing get/set methods, which is what you should be doing otherwise. But at least with properties, it's one named thing per thing instead of (often) two.
I'm thinking about finding another job. I'm watching a project at work fail in slow motion. I work on a batch processing application. It's not badly written in the sense that the original developer was a complete moron. He made some dumb decisions, but it wasn't a complete clusterfuck in the beginning. The problem is that things have changed a lot over the years and a lot of programmers have touched it and didn't address technical debt as they modified it, so overtime it has become bad.
Some developer, who thinks very highly of themselves, was given permission to rewrite it. The problem is that they have done very little to address the actual problems and have managed to create many new ones. I estimate that a single developer could rewrite our application in 6-12 months. So far this rewrite has been in development for 4 years now. They're starting to reach a point where it's close to usable. However, because they failed to actually consider what real issues needed to be solved, the whole thing is now a massive clusterfuck.
Our current batch process does some comparisons and outputs a file with the results before it gets committed to our real database. There are a LOT of advantages to that. The rewrite does away with that. It writes everything directly to the production database. So if there are bugs or bad data generated, our production system is fucking hosed. Additionally, the performance of the rewrite is atrocious. 2 hours in the old system is 2 days with the rewrite. The developer keeps asserting that they can optimize later. It's always "get it working, then make it fast". I looked at the implementation. The data model is so absolutely fucked and does a bajillion JOINs. No amount of SQL indexing is going to resolve the fact that they fundamentally fucked up the data model.
>continued...
Talking to the developer of this rewrite is frustrating. They have a lot of textbook knowledge. They can practically recite CS books from memory. They know all the rules and best practices. The problem is that they seem to have a very poor understanding of actually applying it. It seems they understand everything about good software engineering in the small scale (how to write good simple functions), but have been a complete and total failure at looking at the big picture. They apply KISS (Keep it Simple, Stupid) to individual classes and methods, but the software application as a whole is very convoluted and aims to fix completely non-existent problems.
I want to tell them to stop, but because they're four years into the rewrite, the company has fallen for the fallacy of sunk costs. They're too deep into it to back out now. Everyone, except the lead developer, knows it's the Titanic waiting to happen, but management just sighs and says they sunk too much into it and we have to press forward.
Can you just write programs in java bytecode
One visibly named thing that is. The ability to apply accessibility modifiers on auto implemented properties is somewhat useful, but I I feel like it would be better to just have a full property most of the time.
I feel like it would've been a better idea to make auto implemented properties be able to have the same customizability of the getter/setters as fully manual properties. It's much more useful syntactic sugar that way.
Sounds like your lead developer is a fine programmer but an awful architect. There's no reason to feel bad about that. People have different skills and all but they absolutely should not be in the position to make large architectural decisions about the system.
You were able to 10 years ago. I remember opening some compiled java code in a hex editor to find it quite readable. I imagine it's now more optimized and nasty.
your management are idiots.
LPTHW
>find the video interesting and the guy okay to listen to
>open up the rest of his channel
>"I'm a christian electrical engineer"
>okay what?
>listen to rest of video and see lots of cool projects
>video ends with "science is my verb, christ is my light"
I was not expecting *that* at all.
Yeah, I suppose that would be nice. Then again, it's generally good to use full properties wrapping a named field anyway, because your implementation code can access that field without unnecessarily invoking the property. Also, if you wanted to access the wrapped field elsewhere in your class in the scenario you describe, you'd be out of luck until you refactored. Still, I wouldn't mind it.
user@faggot ~ % ./a.out
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on
Please provide two integers to average, separated by a newline:
1
3
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on
Result of averaging 1 and 3: 512
wat
>without unnecessarily invoking the property
You don't have to worry about that, that would be some pajeet-level shittiness of the optimizer if it didn't inline auto properties' hidden methods into direct access to the hidden backing field.
lmao, even meme professors can't average 2 numbers in C
You mean the book right?
If you're still here, show your professor this:
steve-yegge.blogspot.com
Specifically the section called "Static Typing's Paper Tigers" which is about halfway through.
5 1/2 hours yesterday and another 5 1/2 - 6 hours today, and I now have a working symbol table. It's a little bit of a clusterfuck, and it might become difficult to maintain later on, but it works.
>Maybe if C had the ability to do multiple returns that would be more legitimate.
>Not to mention returning pointers to structures rather than pre-allocating them and modifying is both worse performance-wise and software glitches-wise. Memory leaks are the second most insidious kind of bugs. Stack > Heap.
C has supported returning (and passing, and assigning) structures by value for your entire lifetime.
So I hear a lot of things from Haskellfags that Haskell is apparently super fast using "optimizations only a pure language can do," but how fast is it really? And what are these optimizations?
So how many orders of magnitude slower is Haskell than C for a reasonably complicated program?
Except, my understanding is Haskell unlike C requires a PHD in the Haskell compiler and lazy evaluation evil to optimize, so how fast is a Haskell program that doesn't use advanced Haskell compiler-tricknology?
This is true except defining a structure for every function is rather obnoxious and litters code with one-off structures and boilerplate for extracting the useful data from them. It's easier to pass pointers to shit you want mutated.
Er, yeah. Duh. My bad. But I do want more than auto property behavior most of the time, and in those cases it's important to be able to access the backing field without invoking the property. Now that I think of it, it really is the majority of the time for me. Maybe that's what they expect? I don't know why else they wouldn't have implemented what you're talking about. It must have occured to people working on the language.
I'd been slacking off a bit since my Web Dev final project, but I started working on my own website again.
Gonna check if I can actually write up the scripts for my database, though, because the more I realize, I'm not 100% sure my database is done the most effective way, and I want something relatively fast when I launch. I think I'll copy a lot of what I have but try to make it in order.
Then, I'll aim to finish the login system
Can anyone help out? I'm trying to make a GUI using Visual Basic in order to track the killer's IP address
>GUI
>Visual Basic
Drag, drop, done.
>Track the killer's IP address
What?
I have ZERO context as to what the fuck this even means. How do you know their IP address? How do you know it's changing? You can use a trace, traceroute, maybe?
Who is killer?
Why in the fuck are you using VB, anyway, though?
is this some sort of sophisticated counter-memeing or are you literally under 18?
I'm currently thinking of using datalog for database queries in my program.
I'm working on a basic ATM program in C++ but am having problems with undefined strings,
I need to define "amount" for the withdraw and deposit functions but am unsure where I should define them, I was hoping to put all the functions in a header then call it but it is starting to seem like the header is getting a bit too full for a reasonable header and I'm just sticking half the program in there.
I assume I have to define them in there with the class "Account" so they can be used in the functions right?
I can post a screenshot if I haven't explained my problem well enough.
Uh, no, I have no idea what he's talking about.
By what he said, I can ascertain:
>He needs to create a trace on an IP address
>He wants to use VB to create a GUI for this purpose
>Something is a "killer"
Whether that is a person being searched for by the police or some sort of codename for something else, or even a placeholder like "foo" and "bar", I cannot tell.
>is this some sort of sophisticated counter-memeing
This is a meme?
>or are you literally under 18?
No, I'm slightly autistic. I can't interpret what the fuck he's trying to ask.
Right, but I was just pointing out the fallacy in the idea that you have to use pointers one way or the other if you've already decided to use structures (returning a pointer vs pre-allocating and passing a pointer in).
People get the idea that they should do this because there are so many standard functions that do it, and so few that use struct values (only one I can think of is ldiv), and so the pattern proliferates.
...
>No, I'm slightly autistic. I can't interpret what the fuck he's trying to ask.
You got memed. It's a reference to a notoriously bad scene from CSI.
It's a reference to the totally incompetent technical writing of CSI. The scene: youtube.com
You can replace it with a non-auto-implemented property later without breaking binary compatibility.
I see.
And damn, that scene is fucking retarded.
Sorry, though, I don't watch almost any American TV. I only watch my animus and YouTubes.
Literally had never seen that before. Ever.
Guess it wasn't the autism, just lack of information this time; neat!
What the fuck
Also, properties can be part of an interface while fields can't, making auto-properties more useful than fields for mocks creation/generally having a more consistent public contract.
Except there's no reason why an interface system can't include fields. That shit is the designers forcing their style down your throat just like python and its whitespaces scope.
>You can use a trace, traceroute
you could use a tracer T: youtube.com
If anything is a deficiency it's the fact that there's any difference at all, at the implementation level, between auto-implemented properties and fields. someone could implement a new language tomorrow and use field syntax for something that is basically "really" something like an auto-property.
One thing I don't like about C# is that you can't have a get-only auto property backed by a readonly field that can be initialized in the constructor.
>Time Elasped
Am I weird that this bothers me more than literally everything else in the video? (plus it's unprofessional to have the capture program in the video and be spazzing the mouse around)
>you can't have a get-only auto property backed by a readonly field that can be initialized in the constructor
You mean like this?
dotnetfiddle.net
You can already do that in C++ with operator overloading though. Overload the = operator and the -> and you get just that.
wtf?
Why are you using Java shit in C?
Admittedly, I wasn't super familiar with C functions like printf/scanf, so I did need to look up formatting, b/c I got dogshit answers. (I'm from C++, and I haven't used much C)
But, anyway, this?
#include
#include
int main(int argc, char** args)
{
int a = 0;
int b = 0;
double c = 0.0;
printf("Please enter some ints to average!\n");
scanf("%d %d", &a, &b);
printf("Current values are: %d, %d, %f\n\n", a, b, c);
c = ((((double)a) + ((double)b))/2.0);
printf("The average of %d and %d is %f.\n", a, b, c);
return 0;
}
I can't believe I'm not being memed
Won't overflow but may lose precision depending on the size of double and int.
It won't on a typical system with int having 32 bits and double being ieee. Double has 17 digits of precision and INT_MAX is around 2 billion, so 10 digits.
hey Sup Forums can you help me out pls
all i want to do is a simple factorial function but im stuck
int factorial(int x)
{
int i;
for(i=1; i < x; i++)
x *= i;
return x;
}
Quick! Stop what you're doing and invert a binary tree!
Your code works perfectly
reported for misogyny
but it let me not compile just this way
do i need add #include and int main()
cause it gave me data definition has no type or storage class
There's 2 problems. First fact(0) = 0, and your code if it worked wouldn't do that. Second, as the for loop iterates, x grows in size too, so let's go step by step:
>fact(5)
>i = 1, x = 5
>i = 2, x = 10
>i = 3, x = 30
>i = 4, x = 120
>i = 5, x = 720
>i = 6, x = 720*6
Essentially the loop never terminates because x grows too. Well it never terminates until x overflows and becomes negative.
Here is fixed code:
int fact(int x) {
int i;
int x_orig = x;
for(int i = 1; i < x_orig; i++) {
printf("%i\n",x);
x*=i;
}
return x;
}
I left the printf in there because I was intially confused and thought it worked, I used the printf for debugging.
No it doesn't.
Its slow
I should add, it's fixed except for that fact(0) produces an incorrect result.
If you're compiling an executable you need a main function. That code doesn't have any stdio calls though, but the one I posted does.
i thank you im try it right now
Damn I'm a dummy and I didn't realize that it doesn't work.
Fuck mutable state man.
I need to get back to studying, or go to sleep.
im not sure whats wrong when i tried your source but i got errors for no declaration of parameters and stuff
here is the code that worked fine for me:
#include
int main()
{
int c, n, fact = 1;
printf("BLABLA\n");
scanf("%d", &n);
for (c = 1; c
you forgot to declare fact right?
Huh? It works on my system.
$ more test.c
#include
int fact(int x) {
int i;
int x_orig = x;
for(i = 1; i < x_orig; i++) {
printf("%i\n",x);
x*=i;
}
return x;
}
int main() {
printf("%i\n",fact(5));
}
$ gcc -o test test.c
$ ./test
5
5
10
30
120
Oh. I see your problem
for(int i = 1; i< x_orig; i++)
is c99 since the declaration is moved inside the for loop.
You have to compile it with the flag -std=c99.