What are you working on, Sup Forums?
Old thread:
What are you working on, Sup Forums?
Old thread:
Other urls found in this thread:
I'm finding it difficult to come up with novel solutions to the exercises in K&R
then I look at other peoples' solutions and see how obvious it was
will this go away with practice and time
do I really have to check every malloc/realloc for nulls?
>will this go away with practice and time
Yes
Yes, especially realloc.
Yes, the simplest way to do it is to just create a wrapper for malloc/calloc/realloc where you do NULL checking and call those instead.
what if I just leave asserts on and assert after every malloc/realloc/calloc
I got an assignment to see if two rectangles in a plane intersect in my cs class. After thinking about it for a bit, I came up with an original solution that was worse than o (n^2) by representing each rectangle as a series of points and checking if any of the points in rectangle a were in rectangle b. The TA that graded it said it was the most inefficient thing he had ever seen that worked, but I was like one of four people in the class of 200 who didn't just look it up on stack overflow and copy and paste the o (1) solution. I learned to model more of my cases by hand and find patterns when considering how to find the solution.
Chew on the problem for as long as you need until you can solve it yourself in some way; then when you see the optimal solution you'll really learn a lot by seeing how you thought versus how others saw it.
asserts are usually excluded for release builds, but you could always do that if you just want to halt execution.
Yes, because those functions return null if you failed to get the memory you asked for, and nothing else will tell you that.
what happened to the people that cheated?
But yeah, linear types + monadic regions are the superior form of resource management anyways
They get 0s. Our school uses the MOSS system for cs submissions.
Is there a difference between the stack for static memory allocation in c and the call stack? Are they the same thing?
Same thing
Short answer: yes. That’s why buffer overflows are so dangerous because you risk overwriting the return address.
Long, more correct answer: C itself doesn’t have a concept of stack, that’s an implementation issue. C only know about scopes.
Thanks
Lmfao
For each point pair (Rect A & Rect B) check if the distance between any of them is negative, horizontally and vertically
No. Depending on your platform you are probably already in a state where you can't recover from malloc failing.
how 2 have a nice job without becoming corporate?
how do you guys come up with ideas for novel libraries / crates / gems / whatever? I see so many github repos filled with neat and interesting projects and contributions and I don't know how one even gets to the point where they can produce something interesting and novel that other devs will use.
If you do interesting things to begin with you'll encounter cases where a library doesn't exist for what you are working on.
Writing libraries without already a program in which you want to use them is folly.
why aren't you programming in ++C?
Is there a single language today that will still be in use 100 years from now? Or will all software be completely alien and different from today? Will machines create all software?
>perhaps java is ++C
wew
C, Fortran, Cobol, Lisp
>that image
It's like walking in on your Indian roommate jacking off, except more awkward.
from the perspective of someone who has no idea what they're talking about but has some knowledge on the history of the subject...
IF there are no major breakthroughs in computer architecture and instruction sets remain similar to how they have been for the past 40-60 or so years, i can see low level languages (assembly, c, cobol, etc) remaining mostly the same.
if some super weird shit happens and we suddenly have this new way to develop computers that's much better than the old way, it would probably take 100 years itself for people to adapt to it because backwards compatibility is so important (iirc companies like motorola did a lot of stupid shit developing early architecture to make sure existing programs would be backwards compatible).
higher level languages will constantly be evolving and in 100 years will probably be some super weird abstract shit that's designed to just werk.
there will likely be new patterns and practices that will change the way programs are written too, so while some languages may remain unchanged, how their written could take a new form. though i doubt you'd see much of this for low level languages.
>developing early architecture to make sure existing programs would be backwards compatible
i mean they wanted to make sure that the new architecture they were developing would be compatible with existing software that they had written
what languages should I stick with if I still want a high paying job in 30 years?
First 5 years: C++
Later: system architect
i guess it depends on what you're doing?
on the back end, you'd probably do well enough sticking to shit like c, c++.
on the front end, whichever language is the new hot thing cause that's what everyone else is using.
ideally, it really doesn't matter. the language doesn't mean shit as a software engineer. sure, some languages offer features that others don't, and some languages might instill bad practices, but what's really important is your ability to learn new shit and put things together. if you can't do that, you're not getting paid no matter what language you're working in.
Learning C# basics. It's not going well. Can anyone explain to me why this doesn't work and how to fix it so that I don't just throw my hands up in the air and buy a visual scripting program?
void OnButtonDown(){
flash.SetActive(true);
{
yield return new WaitForSeconds(1f);
flash.SetActive(false);
}
this is why math is important for programmers. by at least reviewing some highschool math , the solution would be clear in your head from the start
>representing each rectangle as a series of points and checking if any of the points in rectangle a were in rectangle b.
wtf lol
the onButtonDown is never called?, read about delegates
I don't think the button is the problem. If the WaitForSeconds function is removed, the button press makes the flash Panel visible, I just can't get it to disappear again.
Damn she's THICCC
(You)
For the past two years everyone in my CS classes has been programming circles around me :(
How can I improve?? I think I may be stupid. I still struggle with java. Meanwhile my classmates are making malware, webcrawlers, websites, lisp scripts, servers, blockchain apps and complex interactive apps in general
Where did I go wrong? I feel so behind here this is ridiculous
Just did the anagram challenge over here:with an emphasis on efficiency.
Is there an easier / more efficient way of doing this?
#define LETTERS_IN_ALPHABET 26
#define UPPER_TO_LOWERCASE 0x20
int is_anagram(const char* s1, const char* s2, int lengths)
{
/* Doesn't account for spaces */
int index;
char alphabet_1[LETTERS_IN_ALPHABET], alphabet_2[LETTERS_IN_ALPHABET];
char current;
/* initialize this array*/
for(index = 0; index < LETTERS_IN_ALPHABET; index++)
alphabet_1[index] = alphabet_2[index] = 0;
/* count number of each typ eof character in each string */
for(index = 0; index < lengths; index++)
{
/* account for s1 characters */
current = s1[index];
alphabet_1[ (current | UPPER_TO_LOWERCASE) - 'a']++;
/* Do same for s2 */
current = s2[index];
alphabet_2[ (current | UPPER_TO_LOWERCASE) - 'a']++;
}
/* Check to see if amount of characters in each string is equal */
for(index = 0; index < LETTERS_IN_ALPHABET; index++)
if(alphabet_1[index] != alphabet_2[index]) return 0;
return 1;
}
Why do Indians love java?
So I'm a little uncertain how to handle variables and it seems like the only difference between these is actually writing the equation out, which should I be using? Also why not assign results as variables, generally speaking?
(I'm aware I should be using a different parse, ignore that)
int x, y, z;
Console.WriteLine("Enter your first number.");
x = int.Parse(Console.ReadLine());
Console.WriteLine("Enter your second number.");
y = int.Parse(Console.ReadLine());
Console.WriteLine("Enter your third number.");
z = int.Parse(Console.ReadLine());
Console.WriteLine("Result 1: " + (x + y + z));
Console.WriteLine("Result 2: " + (x + y - z));
Console.ReadLine();
or
int x, y, z;
Console.WriteLine("Enter your first number.");
x = int.Parse(Console.ReadLine());
Console.WriteLine("Enter your second number.");
y = int.Parse(Console.ReadLine());
Console.WriteLine("Enter your third number.");
z = int.Parse(Console.ReadLine());
Console.WriteLine("Result: {0}+{1}+{2}={3}, {0}+{1}-{2}={4}",
x, y, z, x + y + z, x + y - z);
Console.ReadLine();
It's not limited to one nationality. Java is perhaps the most employable programming language today.
are you female?
In other words, even though you're trying to come up with somewhere new to poo, you're really stuck pooing in the street. The place you really want to poo is ++Java, which would be new and improved poo language. Perhaps C-shart is ++Java
trying to make a simple fucking calculator but its screaming at me something about the damn char
#include
int add(int firstNumber, int secondNumber);
int subtract(int firstNumber,int secondNumber);
int multi(int firstNumber, int secondNumber);
int main() {
char operator;
int firstNumber,secondNumber;
printf("Enter operator +, -, *");
scanf("%c", &operator);
printf("Enter two numbers : ");
scanf("%d, %d",&firstNumber, &secondNumber);
if (operator == "+") {
int result = add(firstNumber, secondNumber);
printf("result");
}
if (operator == "-") {
int result = subtract(firstNumber, secondNumber);
printf("result");
}
if (operator == "*") {
int result = multi(firstNumber, secondNumber);
printf("result");
}
return 0;
}
int add(int x, int y) {
return x + y;
}
int subtract(int x,int y) {
return x - y;
}
int multi(int x, int y) {
return x * y;
}
Yes sir that is V as in Victor
why is it so hard to find a straight answer for how you're supposed to render with the same shader program but with a different texture? you just update the sampler uniform right? no glActiveTexture/glBindTexture/other bullshit?
Planar reflections in opengl!
What do you even do to recover from *alloc returning null? Exit the program with an error?
Neat how does it work?
just sleep and come back when there's more memory
Double quotes usually indicates a string which includes a null terminating character. Single quotes is for a character literal.
i fucking hate mnemonics
as long as you never dereference a null pointer, you're good
the reflection is the cube rendered "upside down"
Are you using something to learn this or just browsing through the docs? I've seen you post these before and you've made some good progress.
that's way simpler than what I thought it would be. I'm kind of disappointed.
I'm working through open.gl
The documentation is basically impenetrable unless you already know how GL works.
Don't bother with official GL books either, they're basically documentation and not really beginner-friendly.
should be
printf(result);
or
printf("%d",result);
Please elaborate. What is it you struggle to understand.
Also quickly do this fizzbuz test without looking for answers online, just to check where you are programming-wise:
Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”
Apparently it's the easiest/most efficient way to do reflections
I still think some kind of reflective ray/pixel tracing thing should be faster. It just makes more sense to me that re-using pixel data already created (assuming no culling) is faster than rendering objects twice.
also check out bjarne stroustrups book Programming Principles and Practice using C++ if you'd like to see how to implement a more advanced calculator that has operator precedence and basic recursive parsing techniques that are used in compilers.
thank you, but it's still yelling at me about the char. something is fucking up with the char
...
try using single quotes around '+' etc
And this is why Software Engineers are brainlets. This problem is just geometry, not CS. Not everything can be discretized.
I don't know, I think rendering the object twice would be faster than using raytracing to recreate the scene from different angle, don't know what pixel tracing is.
You made a cube that disappears?
When it comes to building a portfolio are you allowed to at least show screenshots of proprietary software you worked on?
Last year a group and I worked with a company to build a new prototype of one of their existing software. We didn't sign anything, but they were clear on keeping the repo and code private. We did show what we managed to finish in front of other companies in our final presentation so is that sort of like an OK in that regard?
>O(n^2)
What are you talking about dude? What is even n in the problem? No matter what solution you come up with it will be O(1) since nothing is varying. Maybe you should look into big oh notation more.
Forget about your algorithm is probably fine. You're obsesing over stupid details.
If it works its good. Optimize later after everything works.
does the /dpg/ have a channel on rizon??
if you're given this problem and you don't immediately think to subtract points, you're a literal retard and don't deserve your CS degree.
rendering is what the gpu is designed to do. for reflections in more general scenes there is screen space reflection but it's heavy and has its limitations, can't see behind corners or from outside of the viewport
Yeah that makes sense. I was just saying his algorithm is O(1) no matter how shitty it is unless hes really doing something stupid like dividing the rectangle into sub rectangles and checking all those points.
Is rizon run by the feds?
Does anyone else here have a developer signature?
I personally like having a small piece of code tucked away between endless other lines where, if certain arbitrary conditions are met a small jingle will play or the sprite will appear, pic related.
I know a friend of mine who just likes to comment weird stuff.
>Does anyone else here have a developer signature?
Yes I include a base64 encoded picture of hitler in every project I work on.
Someday someone will read through my code and find all the hidden hitlers.
How do you feel about side effects, Sup Forums?
static float fps, prev;
if ((fps = framerate_avg()) != prev)
printf("%.1f FPS\r", (prev = fps));
How many original ways can you solve this simple problem without it getting flagged by some brain damaged "plagiarism" detection software?
Sounds like to me any solution would be very similar to one another.
whitespace, function names, variable names, tabs/spaces, order of doing things all help to make your solution more unique.
Most systems like that just make it aware to a human who passes ultimate judgement on it, especially for software.
Wow so if I change little things and move stuff around in the file I can defeat it? That's just great.
A test whose results or lack thereof don't prove anything is completely useless.
You'd have to change quite a bit because no one would care about plagiarism on a fizzbuzz solution. The program would probably be more medium, in size and you'd still test 80-90% the same unless you changed a lot.
Why do you assign variables and use them in the same expression? Just makes it pointlessly confusing, when someone could look at that and understand it in a second if you used seperate statements.
Generics and after flew over. Even something simple as to why I would use more than one class file for a single programming prompt/example. I can't remember when or why Im supposed to decide to do this.
Also I think I could do it using if and mod in my 3 tests cases. Yes?
I don't write software so other people can maintain it after me.
How do you keep motivation to keep coding Sup Forums? I work as a developer and I love working on new stuff, but fixing bugs? Oh my GOD! I hate it, and I have many items to work on right now.
not him but whatever, it's a little more complicated. Like for example, you have to iterate from 1-100 vs the usual 0-99 for arrays. Also code like this:
if (i % 3 == 0 && i % 5 == 0) printf("fizzbuzz\n");
if (i % 3 == 0) printf("fizz\n");
if (i % 3 == 0) printf("buzz\n");
won't work. The easiest way to see if you can do something small like that is to just try to do it instead of asking if a few elements are what it takes. Because you might think it's easy and then something obscure gyps you.
Generics aren't that hard. Ie if you had code like:
int add_func(int a, int b) { return a + b; }
you could add 2 int's, but it wouldn't work for doubles or floats. So you couldwrite this
template T add_func(T a, T b) { return a + b; }
and the function will replace T with whatever types you're adding at the moment.
Can you guys help with c++ im trying.
#include
#include
#include
using namespace std;
void getData(int [], int);
void print(const int [], int);
int getLowest(int [], int);
int getHighest(int [], int);
int main()
{
const int NUM_EMPLOYEES = 6;
int hours[NUM_EMPLOYEES];
getData(hours, NUM_EMPLOYEES);
print(hours, NUM_EMPLOYEES);
int lowest;
getLowest(hours, NUM_EMPLOYEES);
cout
>How do you keep motivation to keep coding Sup Forums?
How do you even START coding? I have this project and I read/learn stuff all the time that's related to it, I'm pretty confident about my ability to finish it, but actually starting to work on it is another matter... I just keep putting it off
its kinda like writing. once you start just keep typing and worry about fixing little shit later
lads i am starting a new course called more or less " introduction to object oriented programming for physics" in python
can you help a spaghetti user to find good resources to learn python and pass the course with the highest score possible ? thanks
Do you use windows?
Rewrite in in C.
ikr, i knew elementary C and started a C++ class at school. C is much better.
I dont even want the answer I just wanna know what I'm doing wrong so I can fix it.
yes, i have already installed visual studio professional ( free thanks to the university) and anaconda and i have almost concluded the basic tutorial on learnpython.org.
i use mathematica almost everyday for small stuff and i remember a bit of c .
project Euler comes to mind. just do them in python i suppose
isn't there some site or book where the author propose project and then at the end of the book he provides the solution? project euler does not show the solutions and i think i am not ready for that level right now, i use python from just 2-3 days
You're not setting lowest and highest in main to the result of the function calls. You're just making highest and lowest variables with whatever's in memory at those spots and then running the functions without assigning the return values to anything. Also you start at 1 a couple of times when you're iterating through the array. Also also put srand at the top of main so you don't fuck your mind if you call getData twice.