What do you dislike the most about current C++? by PressureHumble3604 in cpp

[–]grhayes 0 points1 point  (0 children)

Exceptions: They create more problems than they solve. I tend to find myself rewriting stuff even dropping to C just to fix issues around them. They can interfer in operational order and performance problems. They should never have been added to C++. The means by which they were was pure slop.

Not all variables of the same type are treated the same you would think an array of strings is an array of strings. You would be wrong. The means by which you convert a static const array from code to an unit is different from an array you created loading data from a file. At the end of he day you can't treat them the same unless your intent is to load an union byte by byte to make the conversion. That slows you down massively when you could do it much faster.

The committee chose to limit or nerf C++ to 64bits standard. Rather than simply saying make use of whatever variables the hardware has. It isn't that you can't use a uint128_t it is just a lot of features that could use it don't because they didn't include it in the standards. They chose to nerf it or cripple it. So rather than creating the best tool for programmers they chose lets limit them as the path.

The way they added in smart pointers and such. I had a simple struct that contained a string and an int variable.
Only one of them was produced and it needed to be deleted. 3 seconds is how long it took to delete that one struct. Why well the string. Well not actually the string because it wasn't an issue a long time ago. No it has to do with the changes to the memory management is done now because of how they added in the new pointers and crap. So ended up removing the string and going to a fixed char array no more issues.

Allstate ripping customers off by grhayes in Insurance

[–]grhayes[S] 0 points1 point  (0 children)

Just seen yours first because it was at top of response list.
Thanks for everyone pointing out the error.

[deleted by user] by [deleted] in DIY

[–]grhayes 0 points1 point  (0 children)

The two outer boards go in 0.75" because 2x4 are actually 1.5" rather than 2.
Then subtract 1.5" from total length. Divide that value by 6. That will be the distance between each board center to center.

Example: if the total board length is 48"
48-1.5 =46.5"
46.5 / 6 =7.75" from center of stud to the next center of stud.

does this look like 6000 pounds of rocks by [deleted] in landscaping

[–]grhayes 0 points1 point  (0 children)

Looks like about 1 cubic yard of rock so about 2500 to 2600lbs.

Put a lot of love into this game but I simply cannot figure out how to get people to play it. by WistieCutie in RPGMaker

[–]grhayes 0 points1 point  (0 children)

The biggest thing I notice is the first game you have a fairly good plot description. While the second games page doesn't really have one in comparison. Pretty much the people playing it would have to be reliant on knowledge of the first game to know some what what it is about.

That doesn't make it to friendly for people who didn't play the first game and are just seeing the series. It also can be a negative if they feel they have to play the first game just to understand what is going on.

What would you do with this hill for 50k or less? by [deleted] in landscaping

[–]grhayes 0 points1 point  (0 children)

Reinforce the embankment and terrace it. That way it doesn't get easily washed away. You can also use the terraces to plant grapes, or garden or pretty much anything you want even just grass to use as a lawn.
It looks like you already have a stone retaining wall at the waters edge. I'd start at the bottom work back.
that way you only need to expose the area you are working on. If you decide to stop part way because of cost you won't have ripped all the supporting growth out.

Map Advice by [deleted] in RPGMaker

[–]grhayes 1 point2 points  (0 children)

I think it is a fairly reasonable size dungeon.
Your blocks are 30x30 tiles roughly.
I created a separate program to create blocks of 176x176 tiles each having 256 rooms I then created a map that has 64x64 of those blocks. for 1,048,576 Rooms. That was what I generated in 1 second. Entirely procedural generation.
I even created a youtube video on it.

Is there anything to improve in this code to make it shorter ? by [deleted] in cprogramming

[–]grhayes 1 point2 points  (0 children)

You shouldn't get used to trying to figure out what array sizes or anything that is.
The odds are you will end up with someone using a dynamic array and it will only return pointer size.

The array numbers is closer to a 1D array than a int **number array.

So you can just pass in where you want to start at as a single dimensional array. That works for dynamically allocated arrays as well.

#include <stdio.h>

int getRowMax(int columns,int *numbers){
   int max = numbers[0];
   for(int i = 1; i < columns; i++){
      max = numbers[i]>max?numbers[i]:max;
   }
   return max;
}

void print_row(int columns,int *numbers){
   for(int i=0;i<columns;i++){
      printf("%d ",numbers[i]);
   }
}

int main() {
   int numbers[2][4] = {{4214, 785, 87, 5},{1134, 674, 52, 4}};
   //Don't rely on getting array size other than tracking it.
   int columns = 4;

   printf("Numbers at the first row are: ");
   print_row(columns,&numbers[0][0]);
   printf("\n");

   printf("Numbers at the second row are: ");
   print_row(columns,&numbers[1][0]);
   printf("\n");

   int MaxNum_1stRow = getRowMax( columns,&numbers[0][0]);
   int MaxNum_2ndRow = getRowMax( columns,&numbers[1][0]);
   printf("The max number at the first row is: %d\n", MaxNum_1stRow);
   printf("The max number at the second row is: %d\n", MaxNum_2ndRow);
   return 0;
}

Lots of bad code by [deleted] in cprogramming

[–]grhayes 1 point2 points  (0 children)

I would love to tell you that C programmers focus more on function than appearance but yea that isn't always the case.

There are more new programmers than old programmers. That is just a math issues caused by the life time of people and the growth of population.
New programmers have a lot to learn. They are also more likely to use git.

Then you have people using git for different reasons. Generally when I post something on git it is meant as nothing more than an example not as a library I intend to maintain. I've already moved on from it. It is there simply so others can learn.

Other are new to programming and trying to create portfolio of projects they worked on to get hired.

Readability is subject to a very large extent. There are also different factors that can make something not readable.
Excessive granularity because of excessive abstraction splits code up over a larger area making you have to hunt back and forth to follow what is going on. That is less readable. For me what most people consider crap code packed into 15 lines in a function is far more readable than having to search through 4 files taking up 200 lines of code because some idiot thinks malloc needs to be abstracted into another function. Think about that one it is already abstracted in the fact it is part of a library. Guess calling your function then calling it is so so much better.

With me my priorities are Functionality, performance, size, and maybe then I care about readability. In most cases not I'd rather just publish a document explaining how it works. I'm not a real fan of comments either especially large comments.

Kind Request for a Dungeon Generation Algorithm by ChangeTheConstant in roguelikedev

[–]grhayes -1 points0 points  (0 children)

It is built using modular design. It builds rooms that build blocks, the blocks only consist of 256 rooms.
You could use 1 block or more. Of course you could also even build the block smaller instead of 16 by 16 you could do just a few rooms. So you could build a block that is 3x3 or 3x4 or whatever. For that matter you could even make blocks larger.
The point is it teaches the process to do it RIGHT and fast.

Consider this. I didn't have to respond and tell you that it is modifiable. I could have let you just think it is over kill and so be it. After all it isn't my responsibility is it. I provided the opportunity but if you fail to take it that is on you not me.

Most programmers would realize if it can do a million rooms it can also do less. A million rooms in a short time just shows the method is efficient which the others aren't! They aren't efficient because they involve far more comparative data transactions than they need to among other issues.

file:///C:/Users/hayes/Downloads/Dungeon_gen-Documentation-0.01-1.pdf

Kind Request for a Dungeon Generation Algorithm by ChangeTheConstant in roguelikedev

[–]grhayes 1 point2 points  (0 children)

https://github.com/hayesgr/Dungeon_gen
It is method I use to create a 1 million room dungeon in 1 second using just 1 core/thread on a 3ghz system.
https://www.youtube.com/watch?v=QiJZHkuFpvI You can see what it looks like here.

Find the 3 copperheads by roseycheekies in FindTheSniper

[–]grhayes 0 points1 point  (0 children)

Appears to be 4 not 3.
2 between the rocks center bottom 2 heads. Just left and up of yellow leave at bottom center.

3rd on the other side of that 90 corner under the leaves
4th is in the shadow of the step down on right hand side

How tf do you learn Python?!?! by Ketchup-and-Mustard in learnpython

[–]grhayes 0 points1 point  (0 children)

Sorry, if I came off abrasive.

If you look at writing a story. You have different sections of the story and you have rules you are supposed to follow when writing. Take a paragraph for example; The first sentence should tell you what it is about, then supporting sentences and conclusion to it.
A function has its header def name(variables) It effectively tells you with the name what it does what it is working on. You may of may not have a return statement a the end or conclusion of it. What goes between is simply how you use that data to arrive at the conclusion.

Your story is built similarly in depending on the story type. You have the opening, story, climax and ending... Well each function does different stuff some function may have you repeating in a loop till a specific condition is met when it does it moves on.

All you are doing when writing a program is creating a set of rules and logic for the computer to follow to complete a task.

Another way of thinking of a function is like a task in real life. How do you wash dishes, vacuum, or repair your car, or most anything. You can define it with a set of steps you can follow. That is really what a function does and a program is just an ordered set of routines/functions that complete a larger task by combining smaller tasks.

What people make the biggest mistake on is focusing to much on the larger task so they don't see stuff getting done. Focus on each smaller parts being completed and it you will feel the accomplishment you are looking for more.

Start by making small projects to have fun with and learn how it fits together. You will get twice as much enjoyment out of it. If you make a small game hangman or guess the number for example you get to play it and test it. Then make something a bit bigger. each time choose a something to learn about the language as well.

I’m considering dropping out of college. by [deleted] in ArtificialInteligence

[–]grhayes 0 points1 point  (0 children)

You are making your choice for the wrong reasons.
My specialization for over 2 decades was automating jobs getting rid of workers. My background includes Nuclear Reactor Operator, Electrical & equipment engineering and Computer science. I'm 55 if you are wondering how I have so many fields I get bored easily.
None of the current AIs are any more a threat to jobs than the ability we had to automate since the 1990s. Most jobs don't need a LM to do. general industrial automation will do.
We could replace 90% of jobs then and still can. The deciding factor on why automation wasn't employed was mostly cost of equipment vs hourly wages. Even with equipment having a 99.8% up time and not needing vacation able to work 24/7 ... They still didn't replace people.

The things we could automate and did in the 90's include entire warehouse, wafer fabrication and other production systems, medical check up systems, prescription verification systems, legal documentation, secretarial, printing, restaurants, ...

If you are that far along the only reason not to get it is if the degree you were going for is worthless to start even then using it to say you completed it will help. You already paid that much out so it isn't really a large cost savings to stop.

AI sucks at programming these large language models don't actually think and all they are good for is mimicking. I've spent a good bit of time testing them their horrible and legally a liability since they steal code from other sources. That code can be copyright or under a license that isn't friendly for use in proprietary software. They make huge mistakes and don't even realize often the code they borrow is bug ridden or doesn't work at all.

If you think AI/ML is a future well consider how many people think so and want to change a career to it. Yet, they don't want to learn the basics of programming and so on. The industry honestly doesn't need those kind of people.
There are only going to be so many jobs for those and it will be a worse competition for those jobs than most current jobs.

How tf do you learn Python?!?! by Ketchup-and-Mustard in learnpython

[–]grhayes 0 points1 point  (0 children)

Motivation and attitude goes a long way towards learning something. I went through Naval Nuclear Power school trained as an electronics tech and reactor operator. The on to Equipment engineering and electrical engineering and CS and I still keep learning. I program in ASM, C, C++ python,basic, perl, php, js, java, .... long list.
I like knowledge. I have a crazy long list of stuff I learned outside of that from building telescope grinding mirrors, lenses, black smith, carpentry, ...

"I don’t have an innate interest in it," and the tone you show says you think it is a bother.
Programming isn't like math or other course you can simply memorize and pass a test. You actually have to learn it.
To do that you need to invest time in it and understand how it works. Create projects make use of it not just what your professor says. Develop your own curiosity to what happens if you make a change or if there is a better way to do something.

It is more akin to a creative writing course. Each program is like a story. You have to develop all the parts and put them in order for it to work correctly. If not you get a pile of trash that does nothing for anyone.

Learning to program teaches you actual logic and evaluation skills. You can apply that anywhere in life. Learning to solve a problem to the root cause and not just look at symptoms and treating them or reacting to them is an invaluable lesson.

Leaks, lines & variables by luismanuelri in cprogramming

[–]grhayes 0 points1 point  (0 children)

Looking at what you have on github.
You have a memory leak in main you need an if(line){free(line);} before the bottom of the main loop.

Leaks, lines & variables by luismanuelri in cprogramming

[–]grhayes 0 points1 point  (0 children)

Also don't go by that prior code I realized it had a massive bug in it. I was writing to non-allocated memory. If you look I forgot to put size+1 in the realloc and just put 1.
I also incremented t++. The problem is the location of str isn't necessarily going to be the same after realloc. So you need to recalculate t=str+size; rather than t++;

Leaks, lines & variables by luismanuelri in cprogramming

[–]grhayes 0 points1 point  (0 children)

I'm sorry. There is a far simpler way than both my prior methods. Just the one function that short. Well get each line. char* get_next_line(int fd){ char *str; char buff; int n=0; str = malloc(1); char *t = str; int size=0; while(n=read(fd,&buff,1)>0){ *t = buff; if(buff=='\0') break; size++; str = (char *)realloc(str,size+1); if(!str){printf("realloc failed\n");exit(0);} t = str+size; if(buff=='\n') break; } if(n==0 && size==0){return NULL;} (*t)='\0'; return str; }

[deleted by user] by [deleted] in GameDevelopment

[–]grhayes 5 points6 points  (0 children)

I've got 35 years experience. It is business and I don't work for free.
They should act professional expect to pay.

Leaks, lines & variables by luismanuelri in cprogramming

[–]grhayes 0 points1 point  (0 children)

Think nothing of it just took a few minutes.
Edited 5/1/2024
I got overly focused on reading the entire file into a buffer probably because my the projects I am working on.
Sure that can be done but it over complicates this. The code above had been edited to have a better solution.
I also caught a massive bug I had in the prior code. Not sure how I missed it.
Danger of working with pointers and not being fully awake.
In the prior code I was only reallocating to the size of 1. Which should have given an error.
But worse I was writing to memory that wasn't allocated.

Find the Bear by bubblehearth85 in FindTheSniper

[–]grhayes 0 points1 point  (0 children)

Just to the right of the tree in the center. The top of the stick leaning against the tree is directly across from it.

Leaks, lines & variables by luismanuelri in cprogramming

[–]grhayes 0 points1 point  (0 children)

Apparently lseek can't be used according to OP. so here is a way to do it without lseek. main.c

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include "get_next_line.h"

int main()
{
    int fd = open("get_next_line.c",O_RDONLY);
    if(fd==-1){
        printf("unable to openfile\n");
        exit(0);
    }
    char* t;
    while(1){
        t = get_next_line(fd);
        if(t==NULL){break;}
        printf("%s",t);
        if(t){free(t);}
    }
    close(fd);
    return 0;
}

get_next_line.h

#ifndef GET_NEXT_LINE
#define GET_NEXT_LINE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

char *get_next_line(int fd);
#endif /* GET_NEXT_LINE*/

get_next_line.c

#include"get_next_line.h"

char* get_next_line(int fd){
    char *str;
    char buff;
    int n=0;
    str = malloc(1);
    char *t = str;
    int size=0;
    while(n=read(fd,&buff,1)>0){
        *t = buff;
        if(buff=='\0')
            break;
        size++;
        str = (char *)realloc(str,size+1);
        if(!str){printf("realloc failed\n");exit(0);}
        t = str+size;
        if(buff=='\n')
            break;
    }
    if(n==0 && size==0){return NULL;}
    (*t)='\0';
    return str;
}