/dpt/ - Daily Programming Thread

Old thread: What are you working on, Jow Forums?

Attached: 1537603076722.png (640x800, 378K)

Other urls found in this thread:

pastebin.com/MYw9GKzU
gsamaras.wordpress.com/code/caution-when-reading-char-with-scanf-c/
number-none.com/blow/john_carmack_on_inlined_code.html
madhadron.com/posts/2009-11-13-a-perspective-on-four-languages.html
en.wikipedia.org/wiki/Programming_language_theory
agda.readthedocs.io/en/v2.5.2/language/mixfix-operators.html
pastebin.com/C5ciuKL5
twitter.com/SFWRedditImages

How bad is it if my main() is like 400 lines long? I don't have any duplicate code (anything that's reusable is in its own functions and even files), so I didn't want to just make more functions purely for the sake of having more functions that are only ever called once, from main(). Plus each one would need like 3-4 arguments and maybe some out arguments too.

Given this, is it justifiable to keep my main logic all sequentially in main()? Or should I instead just push it all to separate functions full of arguments by reference?

Bump

JavaScript rocks!

Attached: js_rocks.png (1433x779, 473K)

Bump

static functions are free. Use them if it makes things clearer.

But that's my question, does it? Is easier to walk through ~400-ish lines sequentially, or to jump around between subfunctions following the flow of arguments, arguments by reference, and return values?

Depends on how good the names for your functions are.

>UTF8 strings in C
Is this a recipe for disaster? I fear some of the stupid multibyte symbols would break strlen and strtok

nth for nim!

thank you for using an anime image.

Java > c++

Only now it clicked that the girl in the programming general image is Nagato. How stupid am I?

Future browser based ai application. Not sure what I'll do with it yet. An idea is to make some sort of ai competition website, but I don't know enough anti cheat to make that happen. Alternatively I'll just try to continuously develop a better and better AI at the game. Atm it's me controlling it, but I'm basically only a score system from implementing tensorflow.js

Attached: demo_2.webm (720x810, 2.9M)

UTF-8 is designed to be backwards compatible with ASCII in all the ways C wants it to be
A valid non-null UTF-8 character encoding will never contain a null byte
As for strtok, never use it

Haram

I have a problem with my C program
The loops are not executing right and it's jumping to lines outside of the loop that is supposed to be on.
pastebin.com/MYw9GKzU

Attached: 1407872496888.png (500x354, 42K)

Try to print Control

The problem is when you're using scanf.
gsamaras.wordpress.com/code/caution-when-reading-char-with-scanf-c/
Basically when you type your input: 'n' the is consumed by the next scanf. It can be a really annoying problem to deal with, so I tend to avoid using scanf,

What for?
And in previews prototypes I was using getchar().
I will try mixing both but if that doesn't work what 3rd alternative do I have?

It is easier to understand if the logic is separated out into subtasks that can be treated as black boxes. Usually you only have to read a function's name, not the the 20 lines of its body, to understand what it does. If your main is just a small list of functions then it is much easier to understand, and you will only need to walk line-by-line through the implementation details for the one specific sub-function you care about at the moment.

if real-time performance and efficiency matter then C++ is far better
if safety and reliability is more important then it is a poor decision to ever use unsafe manual-memory langs like C/C++

>go is inexpressive language for brainlets
>rust is a convoluted eyesore

is there a book on sepples that doesn't shoehorn OOP into every program like with java

number-none.com/blow/john_carmack_on_inlined_code.html

Writing Elisp to make my latex a little easier to write.

Whenever I run TeX-command-run-all, it generates a ton of garbage files that aren't useful. I want to make a function that makes it such that I remove files after compilation. Here's what I have so far:
(defun latex-compile-but-remove-files ()
(interactive)
(TeX-command-run-all)
(message " Finished running LaTex! ")
(shell-command
(concat "cd " (pwd)
"; rm '*.aux'\
'*.out'\
'*.fls'\
'*.*latexmk'\
'*.*latexmk'"))
)

However, when I run this function, I get this error:
helm-M-x: Wrong number of arguments: #[(arg) "

Is it normal that I get really demoralized and discouraged by difficult problems in programming?

Attached: 1488575104624.png (899x677, 514K)

when you're a beginner things can seem overwhelming

maven, please, just run my packaged jar and stuff the external dependencies into the classpath from wherever you have them hiding on my machine, please! Oh god please.

unless it aids readability there's no reason to split it up

Okay, good. I'm about two weeks into object oriented and I'm finding it really confusing and frustrating, and I was worried it was just me being dumb or something.

There's no shame in taking your time to solve a problem. If anything it makes you better than the webshits that go out of their way to think about it.

nice

I wouldn't recommend learning OOP until you've spent a while doing procedural programming because you won't see the point of the benefits to what OOP provides

Is it worth to learn Common LISP?

In my opinion cheating is just a part of the game.
People should be rewarded for invalidating the test.

OOP is designed to be intuitive. If you are confused, it is probably some combination of you overthinking it, the examples being contrived with poor use cases, and being thrown a ton of unfamiliar jargon all at once.
Just slow down and get used to it.

that's a very vague question. what are you trying to get out of it?

Programming knowledge. I learned the basics with Pascal in my Automation Technician Program and got interested in programming. I'm about to start Information Systems in college.
This book seems very didactic.
So is it worth? What is it used for?

Attached: 51h6Vm4wOiL.jpg (398x500, 51K)

i don't think (pwd) works here, it actually prints "Directory $PWD" for me.

Most Lisps aren't very widely used. Clojure is probably the most widely used and that one is an odd one out of the bunch. It's cool for learning how programming languages work and how to make your own (Lisp in general, Clojure specifically not so). Lisp programmers will tell you they've used things before they became popular, like garbage collectors, and many "inventions" in IT were just people reusing concepts that Lisp devs have used for years at that point. Not sure how true that it but Lisps are interesting.

madhadron.com/posts/2009-11-13-a-perspective-on-four-languages.html
an article you may find interesting. learning lisp is a valuable mental exercise, you will learn ways of transforming data that you never would even consider using an imperative language like pascal. every programmer should learn a functional language thoroughly enough to understand the benefits of a functional paradigm. that said, common lisp is dated and the real practical value you'd get out of studying it would be applying the principles in some more modern language

Yeah, that's what I'm at with it. I've used OOP in school before and I kinda could use it but I still have no idea why it should be useful for anything. On the other hand, functional programming looks neat.

I feel like Pascal is not a real language, it's kind of ugly too. I don't know how to explain it. I guess I'll wait to see what the course will throw in my way, probably python and C++, then pick a good book. I started an internship and I have a lot of free time there. I want to use it to learn something.
I do have a use for Pascal, though. LPCs can be programmed using a language based on Pascal, but it's just controlling algorithms, simple stuff.

>real practical value you'd get out of studying it would be applying the principles in some more modern language
Which language?

Attached: v = ri.png (684x413, 158K)

>Which language?
that would be totally up to you. my point was that common lisp, like pascal, is dated and has fallen out of use, so the benefit is entirely pedagogical.

if you feel like you're wasting time at your internship and not learning anything then you have more important things to be worrying about than which language you should learn in your excessively free time.

I'm there for the money. third world poorfag here.
I have the automation technician classes in the morning, internship in the afternoon and college (information systems) in the night turn.
The internship is in college, in the IT Department. I'll only be there this semester, from May to October.
I might get a job in the oil extraction area in the next 6 months with my automation tech degree.
So I have to use my free time to learn as much as I can about programming principles.

Learn racket.

No they aren't.

I'm getting started with Java stuff, and I know my final will have to be written using NetBeans, but I've installed both NetBeans and Eclipse to test out basic "hello world" or "sum 2 numbers" crap but I just get a ton of shit like "expecting ; got int" and nothing works. When I try the code on online Java editors, it works just fine. The FUCK am I supposed to do to get NetBeans to do this simple shit

Attached: 1466862801600.jpg (720x720, 75K)

so if i want to develop for the GBA, all i have to do is build binutils and gcc to target the arm processor in it, right? i won't have any libs, sure, but will it generate code that runs on it?

Me again I fixed the scanf functions and the loops is printing the strings in the correct order but the if statements on the middle of the program are not executing even after giving them the proper conditions to run. Like I type 'h' and the statement won't execute even if that should make it work.

Attached: 1454434569288.jpg (591x559, 145K)

Yes they are, retard.

How about you learn the fucking language

Well, I'm trying to, like I said the code I've written works fine on online java compilers, how do I make it work on NetBeans?

that's a great book, remember any ansi list library will still work, even if decades old so the code in that book will run fine. It's a rigorous book too so concepts directly transfer to other languages

again, start by debugging it and figuring out what it's actually doing
add a printf or putchar or whatever to show what the actual value of the variable is each time it's changed

But I do have a debugger and I'm using it.
I can see Control with the value of 'h' or 'l' and those lines are still not running.

oh wait holyshit it just says "guess * 2"
don't you have compiler warnings on? it should be warning you about "statement has no effect" because that doesn't actually DO anything

I tried removing the shell-command bit, but it still doesn't work, so it's definitely an issue with how I'm running the TeX-command-run-all function.

Why is Go mascot a retarded animal?

Why is Lua so unpopular?

it's not?

not really interesting plt wise.

Is he right?

Attached: Screenshot_2019-03-23-07-16-43-046_com.android.chrome.png (1080x1920, 321K)

Of fucking course not.

Because it's made by a Brazilian
Nothing good has ever came out of that shit hole

it's really not that unpopular, it's just niche
it's a scripting language originally designed for engineers who weren't programmers in embedded applications
but these days scripting langs are dominated by idiots who prefer to "import library" rather than do anything themselves

personally i like it because it's one of the few scripting languages with tolerable syntax and has some neat metaprogramming capabilities
the irredeemably shit garbage collector/memory management system, which conks out at 2gb and is the biggest performance cost, and 1 based indices by default are its only real flaws

java is my favorite language
it has issues but it just werks

Attached: confess.png (1229x1160, 58K)

How to make a sorting program where user defines relative value of elements at runtime? Example:
$ sorter.lua anime.txt
Do you like K-ON! or Yuru Yuri more? ([/])
> [
Do you like Gabriel Dropout or Yuru Yuri more? ([/])
> ]
1 K-ON!
2 Yuru Yuri
3 Gabriel Dropout
Note it didn't have to ask for K-ON vs GabDrop, what am I supposed to make it do each time it receives response from user?

>not really interesting plt wise
what the fuck does that even mean

en.wikipedia.org/wiki/Programming_language_theory

beg for forgiveness

you could do a topsort

what does that have to do with the popularity of a language

a programming language can be interesting PLT wise (the language itself, its features, concepts, ...), ecosystem wise (lot of tools a libraries), community wise.

for example, php is trash PLT wise but has a huge ecosystem and an very active community.

Attached: 8Qm40AF.jpg (663x710, 101K)

php is a poor example because it's 100% trash in every aspect

you forgot the most important part you fucking hipster, getting shit done

Post your code. Also, why the fuck are you being forced to use an IDE? If you're forced to use an IDE, why not IntelliJ?

>VMs offer more efficient code
>go makes smaller executables than VM'ed langs
>go uses a lot of RAM
he kinda just pulled three dubious, loosely related statements out of his ass, without actually substantiating his claims.

It's a language designed for embedding inside applications, for the purpose of plugins, settings management, etc. It's only useful in highly specific cases, and good luck writing anything useful in it that isn't an extension to another program. Its standard library lags far behind languages that are actually designed to be used on their own.

>Its standard library lags far behind languages
it doesnt have a standard library

It has some kind of string processing tools at least, I tried using it as a stand-in for python once. Maybe that doesn't count as a "standard library" I guess.

shoo shoo, back to HN

I'm having some difficulties understanding this averaging code. The code comes from Texas Instruments, so it should be up to the highest standards.
Panel_Voltage_Buffer, Battery_Voltage_Buffer, Panel_Current_Buffer, Battery_Current_Buffer are all declared as "uint32_t" variables at the top of the file. How exactly does the code compute the average values?
/*
* Call this function to calculate the average of each ADC channel and convert the ADC *
* values to reflect actual voltage and currents in volts and amps, respectively; the *
* following equations are used and may need to be recalibrated: *
* * Panel_Voltage = (PV_ADC + 14.021) / 13.985 *
* * Battery_Voltage = (BV_ADC - 0.0659) / 15.446 *
* * Panel_Current = (PI_ADC + 1.4595) / 30.581 *
* * Battery_Current = (BI_ADC + 0.6037) / 30.567 *
*/
void Average_MPPT_ADC_Values()
{
Avg_MPPT_Counter = 0;
Prev_Battery_Current = Battery_Current;

#ifdef USE_FLOAT
Panel_Voltage = ((float)((Panel_Voltage_Buffer >> 6) + 15) * (1. / 13.985));
Battery_Voltage = ((float)((Battery_Voltage_Buffer >> 6)) * (1. / 15.446));
Panel_Current = ((float)((Panel_Current_Buffer >> 6) + 2) * (1. / 30.581));
Battery_Current = ((float)((Battery_Current_Buffer >> 6)) * (1. / 30.567));
#else
Panel_Voltage = (Panel_Voltage_Buffer >> 6);
Battery_Voltage = (Battery_Voltage_Buffer >> 6);
Panel_Current = (Panel_Current_Buffer >> 6);
Battery_Current = (Battery_Current_Buffer >> 6);
#endif

Panel_Voltage_Buffer = 0;
Battery_Voltage_Buffer = 0;
Panel_Current_Buffer = 0;
Battery_Current_Buffer = 0;
} // end Average_MPPT_ADC_Values

I didn't get an answer in the stupid question thread so I might as well post here. Sorry for being annoying but a simple answer is fine.

What do I have to know in order to be considered to have "intermediate" or "advanced" knowledge in C++?

I've been skimming over "effective modern C++" and so far it doesn't seem to be too bad but I lack the experience in actually coding C++.

Have you tried actually coding in C++?
Just a suggestion

it doesn't do any averaging as far as I can tell

Is there a good way to use VSCode/vscodium for C++ with CMake and makefiles instead of that tasks.json and launch.json bullshit? I would like to debug and execute in the terminal offered inside vscode.

I am in a similar situation - I think, after being in contact with a C++ programmer with around 5 years of experience, that hands-on work with projects (even personal ones) is what makes the difference. I am currently trying to find some personal projects to start in order to develop better skills and a nice github profile. Doing something like this with someone else would be pretty cool.

It doesn't appear to do any averaging over multiple samples, unless that's being done in hardware. Manufacturer-provided code is usually garbage, by the way. It's a decent source for examples, but don't take it as gospel.

Sort of but nothing really complete so I have little to nothing to show for it. I've been just trying to port some stuff from python but I assume that the point of learning C++ is resource management so that's what I've been trying to look into. The basics of C++ seems to be straight forward but learning C++ is probably a waste of time if I don't apply concepts regarding resource management and optimization right? Basically what I'm asking here is what would I have to know and apply that is specific to C++ that other languages cannot do?

>what would I have to know and apply that is specific to C++ that other languages cannot do?
variables, pointers, and references
memory allocation and deallocation
probably generics if you're coming from a dynamically typed language

C++ idioms are pretty jank compared to other languages.
Proper usage of RAII and move semantics are pretty unique to C++ - you can't call yourself proficient unless you get those concepts. And you can't call yourself an expert until you *get* TMP and SFINAE.

Use devkitpro, it's superbly easy to get code running on various Nintendo platforms including the GBA.

Jow Forumsing a language I saw a couple of days ago but can't remember the name of, you can define operators by placing _ where the parameters go, like _*_ is the function name for overloading multiplication, but you can also define ternary operators like if_then_else_ then you call it with if x then y else z.

Agda?
agda.readthedocs.io/en/v2.5.2/language/mixfix-operators.html

Any ideas for good C++ beginner/intermediate personal projects to actually improve skills? I've been struggling to find some.

Depends.

If you're looking to gain knowledge that you can apply out on the job market, than it's not worth to learn it. Lisp is old and dated, only used in legacy systems, or really niche areas (i think the only main usage lisp sees is research in quantum computing).

However, if you want mental excercises and/or just feel interested in it, then go ahead. Look into whatever interests you. In this case, it is more like a hobby rather than actual knowledge.

I would suggest making a text editor. I made one recently and it was a pleasant experience that taught me some stuff :)

2D single player game? Can start very simple & lots of depth if you enjoy

C++ exceptions are fucking dangerous
>The C++ runtime library shall allocate a static emergency buffer of at least 4K bytes per potential task, up to 64KB. This buffer shall be used only in cases where dynamic allocation of exception objects fails. It shall be allocated in 1KB chunks. At most 16 tasks may use the emergency buffer at any time, for at most 4 nested exceptions, with each exception object (including header) of size at most 1KB. Additional threads are blocked until one of the 16 de-allocates its emergency buffer storage.
throwing an exception can stall the entire thread

I think I'll just buy a physical copy of a good C book. Read code examples and footnotes on Kindle is hell. Also, I just have money to buy 1 (one) book, especially if I'll have to import it.
But thank you all.

Can someone please tell me if I'm a brainlet or not? I'm taking my first CS class and I have to code this text based version of the game battleships and I've spent over 10 fucking hours on this assignment and I'm likely nowhere near done. I'm probably going to fail my diff eq exam I have coming up because I've put off studying to work on this shit.

Be straight with me, how hard is this assignment: pastebin.com/C5ciuKL5

Am I just retarded?

Attached: 9f6.jpg (812x1024, 61K)

10 hours for a beginner for this assignment does not sound like much.
Even if it is, don't worry about it, just keep going.

If it's your first cs class I can see why you might have trouble with that.

Fortunately those notes are quite in depth and actually give you a decent idea of what you need to do (the different functions)

What are you having trouble with?