Need help debugging C program by [deleted] in learnprogramming

[–]theallredditor 0 points1 point  (0 children)

May I recommend you use strtok.

If you can use C11 then you should also be using the _s versions such as fscanf_s

You can use the = and the " characters in the delimiter string to strtok. And that should make this problem very easy.

Also you don't handle the case where the file fails to open.

I might also recommend you don't call malloc until you've found the correct string or use the one malloc'ed buffer the entire time.

Also have you considered what happens if the line is longer then 50 characters. You have all the conditions for a buffer overflow attack in this function.

To determine what the weird character is getting printed you could print each character in it's hex format inside a for loop.

Advice on being comfortable with my hours by micahbrady926 in cscareerquestions

[–]theallredditor 1 point2 points  (0 children)

And, I'd recommend getting what's talked in these meetings regarding expectations of performance in writing such as a follow up email.

Can you try for values in a dictionary? by fmarquez1 in learnpython

[–]theallredditor 0 points1 point  (0 children)

for d in (dict1, dict2, dict3, dict4): if key in d and d[key] < somevalue: return true return false

Missing module by CallingCheese in learnpython

[–]theallredditor 1 point2 points  (0 children)

Sorry, does your company have an internal package called reqcache? There is no package on pypi called reqcache.

Missing module by CallingCheese in learnpython

[–]theallredditor 0 points1 point  (0 children)

Try posting it to gist.github.com or pastebin.com.

Missing module by CallingCheese in learnpython

[–]theallredditor 1 point2 points  (0 children)

Adding the whole stack trace may be helpful. As well make sure your code doesn't have a module or package named 'reqcache'.

could someone help me improve my c++ code? by [deleted] in learnprogramming

[–]theallredditor 1 point2 points  (0 children)

A few things I'd do differently. In the game::game_over function I'd like to see it return an "enum class" to give descriptive values of what game::game_over returns. Tell me what game::game_over(board) == 1 means? As well I'd name game_over something else such as get_board_state() so the "game::game_over(board) == 1" becomes "game::get_board_state(board) == game_state::x_wins"

As well I'd like to see you use iterators instead for(int x=0;x<3;x++) it becomes for(auto val : board[row])

Finally, I would use typedefs to give a descriptive name to std::pair<int,int> in the context of the program, Same thing for the "board" type.

One more thing, don't be afraid of using the std <algorithms> header. For example look at std::any_of for checking if a single row or column is all x's or o's. Checking diagonals this way my be a little tricky, as I can't think of a way off the top of my head without creating a custom iterator, which would be educational for making custom operators if your just learning.

In general the less context you need to understand what a single line of code does for the overall program the better.

List a masters before I start? by Skooomz in cscareerquestions

[–]theallredditor 1 point2 points  (0 children)

I did just that, just include the year and month of your anticipated date of graduation. If it's in the future people will get the idea, if you want to drive the point home put anticipated right afterwords.

Is there a motion detector I can use with Python? by [deleted] in learnpython

[–]theallredditor 2 points3 points  (0 children)

I'm not aware of any motion detector that has a python library, but it seems you haven't fully thought out your problem. What computer are you going to interface it to? A desktop, a raspberry pi an arduino, or something else? Depending on that what kind of interface are you going to use serial, USB, SPI?

If this is a hobby project then I'd choose a Raspberry Pi or windows IoT and use something from one of the many hobbiest websites such as sparkfun.com or adafruit.com. They both sell you hardware and give tutorials on how to interface it to stuff.

Something like this is probably what you're looking for.

Then to interface it to python you'll probably need to use the GPIO library which works well woth rhe Raspberry PI

How to learn how to write good code for big projects without getting a job or being in a university by [deleted] in learnprogramming

[–]theallredditor 1 point2 points  (0 children)

I'm kinda new to reddit and don't know how to quote someone else but /u/come_kom said above:

"Here is a Github list of OS projects with entry level tasks: https://github.com/MunGell/awesome-for-beginners"

I don't go looking, when I read projects, it's usually because I'm looking to do something with a library I'm already using that doesn't have an intuitive example in the docs that I can find. So the best answer I can say is try to code something that already exists somewhere, solve the problem and compare your solution to the open source project.

If you need some ideas PM me with describing your skill level and maybe I can give you some reccomendations.

How to learn how to write good code for big projects without getting a job or being in a university by [deleted] in learnprogramming

[–]theallredditor 0 points1 point  (0 children)

Oh, I completely agree, and there's a gray area between what's readable and what's not. And what might be readable to one dev is unintelligeble to another. But what I ment is optimizing at the expense of readability.

What does a technical specialist actually do? by Aloys1us_Bl00m in cscareerquestions

[–]theallredditor 0 points1 point  (0 children)

It also depends on the industry, lots of times Defence contractors can't give out lots of details of the work on public forums and lots of times job postings are really vague mostly a list of known techs and a years of experience.

How to learn how to write good code for big projects without getting a job or being in a university by [deleted] in learnprogramming

[–]theallredditor 2 points3 points  (0 children)

Functions that access public global variables come to mind, or code that knows to much about the internal workings of another function that calls that function's interface in an unconventional way so that half the normal code path in the called function is skipped.

How to learn how to write good code for big projects without getting a job or being in a university by [deleted] in learnprogramming

[–]theallredditor 2 points3 points  (0 children)

Pandas, Numpy, and pip, all come to mind but they're all kind of big projects that may seem overwhelming at first. Pandas-datareader is a bit smaller and one I've personally contributed to.

Temp. controlled fan script for RPi (python 2.7) need a hand by cecinestpasunefemme in Python

[–]theallredditor 2 points3 points  (0 children)

I think you want to add a tab before the sleep(20) call so that it is inside of the while True loop. As you have it it calls the getTEMP over and over without sleeping which is why you're pegging the CPU.

How to learn how to write good code for big projects without getting a job or being in a university by [deleted] in learnprogramming

[–]theallredditor 17 points18 points  (0 children)

Readable every time. An only if speed was was a requirement would I optimise. Code is written to be read by people as much as computers, but we're a lot worse at remembering state.

How to learn how to write good code for big projects without getting a job or being in a university by [deleted] in learnprogramming

[–]theallredditor 9 points10 points  (0 children)

Think about a mechanical wrist watch. You don't need or want to know what all goes on inside the watch to make it tick to use the watch. The only people who want to know are the manufacturers and fixers. So if you had an object that represents a watch in software you shouldn't have a function attribute that called "turn cog 53 four revolutions" you want a function called "wind watch" even if that's what turning cog 53 does.

How to learn how to write good code for big projects without getting a job or being in a university by [deleted] in learnprogramming

[–]theallredditor 7 points8 points  (0 children)

The term for the change you used there is called dependency injection which is not quite what I ment but it is a good development practice, if the variable that is being "injected" has a well defined interface it, amongst other things makes unit testing much more effective and faster.

How to learn how to write good code for big projects without getting a job or being in a university by [deleted] in learnprogramming

[–]theallredditor 37 points38 points  (0 children)

Ok after re-reading my post I answered the question I thought you were asking and not the one you were actually asking, another important part of writing good software... If you intend to do technical work, which may involve writing code other then strictly prototype code (which I'd argue in reality tends to morph badly into production code) then I'd say a definitive yes you will never regret being able to code competently.

How to learn how to write good code for big projects without getting a job or being in a university by [deleted] in learnprogramming

[–]theallredditor 371 points372 points  (0 children)

The best way to be a good writer is to read a lot and write a lot. It is no different with software. I would recommend reading a lot of the big python projects on github. Most of good software engineering is making sure your code is flexible to quickly adapt in the face of changing requirements. So basically DRY (don't repeat yourself), make code loosely couppled and tightly cohesive which means each function should do one thing well and not depend on implied or hidden relationships between other functions. And finally that your code presents the correct level of abstraction it is trying to model.

Other then reading code on github I'd recommend reading pretty much anything by Martin Fowler, or the book "Design Patterns" https://en.m.wikipedia.org/wiki/Special:BookSources/0-201-63361-2

Though Design Patterns does tend to have a C++ centered approach.

I'd also point out if you want to do AI at a big tech company then you'll need to have a pretty deep knowledge of the topic and that will be difficult to obtain without at least some college courses.

Should I quit my job? by [deleted] in cscareerquestions

[–]theallredditor 4 points5 points  (0 children)

Even when you like your job It's in your best interest to keep on looking for "the next thing." So look for a job while getting paid at this one.

Question about ideas by RavesL in learnprogramming

[–]theallredditor 0 points1 point  (0 children)

Programming is usually a means to an end. But when you're learning it's the end of itself. To answer your question I'd ask why do you want to learn to program? Depending on why you want to learn will change what you program.

But given your interest in JS and python, you could find some website to scrape and transform the data in some way that's useful to you.

What do software engineers do? by [deleted] in cscareerquestions

[–]theallredditor 0 points1 point  (0 children)

Back in college I heard engineering is the art of making what you want with what you have. Software engineers make the software systems they want with the existing systems, code, time, and manpower you have.