[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 35
File: timetocode.webm (2 MB, 1152x648) Image search: [Google]
timetocode.webm
2 MB, 1152x648
This is /dpt/, the best subreddit of /g/

Umaru-chan edition

In this thread:
r/programming
r/compsci
r/ReverseEngineering
r/softwaredevelopment

Filesharing and chat: https://volafile.io/r/kUFzLJ

code of conduct:
no racism
no insult
no sexual harassment
no gender discrimination

wat r u working on, anon-chan ?
>>
File: 0054.jpg (10 KB, 232x218) Image search: [Google]
0054.jpg
10 KB, 232x218
>>51287700
>>
first
>>
File: mvn everything.png (139 KB, 1177x856) Image search: [Google]
mvn everything.png
139 KB, 1177x856
Use Maven they said.
It will simplify development they said.
>>
>>51287850

thanks guy

also I missed the alert somehow on the previous thread
>>
>>51287700
Stop with this shit web m you nigger
>>
Is there anything like nw.js/electron for python or a lisp?

I have a project I want to do and I'm shit at gui. html is
>>
how do I reuse a timer after it's being started or canceled in java?
>>
No link to old thread? You dun goofed.
Making a new thread right now, with proper amount of traps.
>>
Rewriting the linux kernel in Go
>>
>>51287700
Just removed optionals from forward facing API because Objective-C people are too stupid to check for a null pointer.

public typealias NormalCallback = ([AnyObject], SocketAckEmitter) -> Void
>>
A correction for your CoC: "no insult" should be "no insults" or "no insulting". Alternatively, just remove the entire rule altogether, as criticism is vital to improvement.
>>
File: bang.webm (2 MB, 900x506) Image search: [Google]
bang.webm
2 MB, 900x506
Ask your beloved programming literate anything.

>>51287700
>wat r u working on, anon-chan ?
A general utility, state of art, C library for dpt
>>
>>51288035
how do I reuse a timer after it's being started or canceled in java?
>>
>>51288027
>rule
this faggot thinks he can make up rules for /dpt/
>>
>>51288035
There was a second season of this?
Whelp, there goes my night.
>>
>>51288035
>state of art
but you're shit at C, anon!
>>
>>51288035
how come the japanese are such perverts, yet so big fucking introverts?
>>
>>51287700
niggery
>>
>>51288001
>Objective-C people are too stupid to check for a null pointer.

Sounds about right.
>>
>>51288035
>A general utility, state of art, C library for dpt
It's shit, stop working on it now.
>>
File: bully_ranger.jpg (134 KB, 762x613) Image search: [Google]
bully_ranger.jpg
134 KB, 762x613
>>51288027
Or better yet, "no bully".
>>
Which one /g/?
online_streams = filter(is_online, watchlist)

online_streams = [stream for stream in watchlist if is_online(stream)]
>>
>>51288144
suck a fat one, pedo!
>>
File: orchidmantis.webm (802 KB, 480x360) Image search: [Google]
orchidmantis.webm
802 KB, 480x360
>>51288057
you can't, you must instance a new one.

>>51288072
>>51288118
please, don't bully

>>51288085
japan is not a post-christian/islam nation, they have less taboo.
>>
>>51288152
First one is a generator in Python 3 which is inherently more efficient (lazy evaluation)
>>
>>51288167
That's what your mom did to me last night m8.
>>
File: 1446565171206.gif (47 KB, 320x180) Image search: [Google]
1446565171206.gif
47 KB, 320x180
Is it wrong to use 'unsigned' instead of 'int' for loop counters?

Doesn't it make sense that a loop counter should never be less than zero?
>>
>>51288169
so basically use a function that set the timer to a newer one, right?
>>
>>51288196
If you want to absolutely correct, use size_t for loop counters. int will overflow on very large arrays.
>>
>>51288169
>please, don't bully
it's not bullying if it's the truth; you don't know c
>>
https://news.ycombinator.com/item?id=10539551
>>
>>51288218
>you don't know c

It's not like C is inherently hard, it's just [spoiler]not good.[/spoiler]
>>
If I can do a boot loader in asm, is it a massive step to make a small kernel or a reasonable one? What's a reasonable ask project? Beginner level.
>>
>>51288239
that's the thing: it's not hard but somehow anon still can't manage
>>
>>51288255
Sure.
>>
File: packofloli.webm (75 KB, 800x450) Image search: [Google]
packofloli.webm
75 KB, 800x450
>>51288196
Indexed for loop is a relic from the past and unsafe but yes, favor unsigned types if you only need an positive index; The compiler generates better assembly and today's cpus have specific optimizations for unsigned comparisons followed by a jump.

>>51288212
This is not true because, in C, the [] operator is only for pointers

a[x] is same as *((a) + (x)).

x (or a) is supposed to be of type ptrdiff_t here.

>>51288202
Yes but care that java pass by value.

>>51288218
Sorry
>>
>>51288196
Always use size_t. Anybody still using int is just doing it out of muscle memory.
>>
>>51288329
>Anybody still using int is just doing it out of muscle memory.
This.
I really got to get out of that habit.
>>
>>51288328
>>51288212
>>51288212
>>51288329
http://en.cppreference.com/w/c/types/ptrdiff_t
>>
File: 1447009338932.jpg (875 KB, 1261x2049) Image search: [Google]
1447009338932.jpg
875 KB, 1261x2049
>>51288255
https://github.com/littleosbook/littleosbook
>>
>>51288328
ptrdiff_t is for the result of subtracting two pointers. It's pretty much equivalent to ssize_t. size_t is what he wants.
>>
>>51288379
>the result of subtracting two pointers
and what does the [] operator ?
>>
>>51288328
>x (or a) is supposed to be of type ptrdiff_t here
Wrong. It can be any integer type as long as the resulting pointer is valid.
>>
>>51288379
>It's pretty much equivalent to ssize_t
There's no ssize_t in C.
>>
Can I create a global variable from within a function?

Like instead of defining a bunch of a variables for my game, can I just make new variables that are permanent?

Although since it's an RPG with skills and stuff I think I need to define every skill in a variable so their effects can be applied when a character has one of them

I'm using lua


Would there be a more efficient method of checking for X skill and then applying it's bonus?

Currently its basically

MoreDamage = 0
MoreDamageEff = +4

So when MoreDamage = 1 the effect is applied mid combat

I really gotta plan this out more
>>
>>51288422
Adds two pointers (and valid pointers are not negative so no it is not subtraction ever.)
>>
>>51288533
You can't add 2 pointers. You can only subtract them.
>>
>>51287700
Help guys. I need to finish this until tomorrow.

Write a C program which writes the endianness of a machine it's running on.
>>
>>51288476
>Can I create a global variable from within a function?
Depends on the language
>>
>>51288599
You really shouldn't need help on this. Pay more attention in class.
>>
>>51288599
#include <stdio.h>
int main(void)
{
puts("little endian");
}
>>
>>51288552
You are a smug little nigger saying incorrect things and then trying to correct me on technicalities. This topical line truly has nothing to do with the conversation.
>>
>>51288599
int a = 0xAABBCCDD
endianness = *(char*)&a == 0xAA ? ... : ...;
>>
>>51288631
>technicalities
It's called "making correct statements". Your "adds two pointers" is complete nonsense. Also, I didn't say anything else to you.
>>
>>51288630
That program will print the wrong message on big-endian machines. You're of no help, anon.
>>
>>51288658
nobody is going to run it on anything else than little endian
>>
>>51288658
It works because literally no one uses big endian machines, so it works 100% of the time.
>>
>>51288611
Language is lua

But I think what I'll do is just greatly simplify the class system and just have warrior like give +2 to weapon attacks and you can wear armor, wizard gets +2 to spells

Warmage gives +1 to each and such

right now it's a tabletop RPG system essentially
>>
File: wOsEq7N.png (317 KB, 793x3106) Image search: [Google]
wOsEq7N.png
317 KB, 793x3106
>>51288599
http://stackoverflow.com/questions/12791864/c-program-to-check-little-vs-big-endian
>>
>>51285021
Still salty as fuck. Anyone know what I was expected to do.
>>
>>51288687
Just keep popping elements off of each and checking equality?

If you need to preserve the contents, you could make two other stacks and push the contents into those as you're popping, and then after you're done pop the elements of the temp stacks back into the original stacks.
>>
I'm working on a concurrent java program which reads and counts tokens in an XML file, then returns which tokens are the most common. A producer thread reads from the file, and consumer threads count the tokens.

I'm using a ConcurrentHashMap<String, Int> to store the tokens and their frequency. However, it sometimes gets stuck in a race condition and doesn't properly add to the count.

How can I make this happen in a single, atomic operation without serializing my code?

private void countToken(String tok) {
if (tokenFreq.putIfAbsent(tok, 1) != null)
tokenFreq.put(tok, tokenFreq.get(tok) + 1);
}
>>
File: BotEKEh.png (105 KB, 1096x622) Image search: [Google]
BotEKEh.png
105 KB, 1096x622
How does introspection work in statically compiled languages? Is there some sort of metadata stored?
>>
File: 6489.jpg (497 KB, 2560x1440) Image search: [Google]
6489.jpg
497 KB, 2560x1440
>>51288729
equal(stack &a, stack &b):
if a.length != b.length:
return false
stack tA
stack tB
while (!a.empty()):
if (a.peek() != b.peek()):
break
tA.push(a.pop())
tB.push(b.pop())
if tA.length > a.length:
while (!a.empty()):
tA.push(a.pop())
tB.push(b.pop())
a = tA
b = tB
return true
else:
while (!tA.empty()):
a.push(tA.pop())
b.push(tB.pop())
return false
>>
Still pretty new to C++, starting to work on classes now.

How would you assign a value to a new class with each loop? Is it similar to an array?

Basically just want it too look like
newclass1
newclass2
newclassx

for each increment of i and continues to total for each loop

pseudo:
 
int i=0;
class Newclass[i];
int value=0;

for (int i; i<3; i++)
{
cout << "Enter value " << i << ": ";
cin >> value;
Newclass[i].setvalueone(value);
cout << "Enter value " << i << ": ";
cin >> value;
Newclass[i].setvaluetwo(value);

total =+ newclass[i].gettotal();
}
cout << total;


It seems to work ok with storing, but I always end up hanging after a few loops. Feels like this shouldn't work/is jerry rigged.
>>
File: feelsgoodman.jpg (3 KB, 123x126) Image search: [Google]
feelsgoodman.jpg
3 KB, 123x126
>tfw when you abstracted away a huge pile of shit into its own file behind a neat little interface so you can hotswap completely different algorithms with great ease
thanks based OOP
>>
>>51288821
We were given the prototype. Was along the lines of void stack::operator == (stack&). Stack has an underlying array and Im fairly certain I dont have access to private data like the top of the referenced stack It was a test so I definitely put something like this down as the answer though. The worst part was that she gave us so little space which makes methink it was a trivial problem.
>>
>>51288858
new and you wouldnt normally ever do this. Generally taboo and means youre a terrible programmer unless youre dealing with massive amounts of code.
>>
>>51288858
>trying to define variables at run time
Why would you think any programming language would allow this.
>>
>>51288875
>Oh god what have I created...
>Maybe if I just shove it away here nobody will notice... I mean, it works, right?
OOP in a nutshell.
>>
Is it good that I hand write and edit my code before tying and compiling it in the console?
>>
So I'm writing cffi calls in clisp to do linear algebra in a reasonable amount of time and I can't figure out how to increment a pointer returned from a function (to iterate over an array). Also, I know clisp is shit compared to sbcl -- this wasn't my choice.
http://www.clisp.org/impnotes/dffi.html
>>
>>51288956
What decade are you from?
>>
>>51288934
i'm replacing it with an improved version, that's why i abstracted it away. OOP is great for maintainability - i can just make the new one effortlessly with no consideration of the previous implementation, it just has to fulfill the contract of the interface
>>
>>51288821
You're not fucking cute, you're a fucking whore, smiling anime girl, a used-up C++ slut.
>>
>>51288956
no just use an IDE
>>
>>51288996

But I become more error prone that way.
Also my school requires us to hand write code for tests.

I'm guessing though that if I do this too often I might develop a bad habit and work too slow..?
>>
>>51288976
do it functionally or don't do it at all desu senpai
>>
So I'm making this android app and I need some sort of animation after an activity is completed.
A friend made a video for me but the transition is pretty choppy, anyone has some advice for this?
>>
>>51288729
this wont work. How would I make the new stacks from within a member function
>>
>>51288963
What does incrementing the result of http://www.clisp.org/impnotes/dffi.html#c-pointer do, just adds one? Could you just add FFI:SIZEOF the element to the result?
>>
>>51288920
javascript lets you do it in a bunch of ways desu
if you use "objects" as a namespace you can easily add them for an arbitrary string by using the dictionary syntax (myNamespace['newVariable'] = someValue) or you can just use eval()
it's not that unusual
>>
File: HST-SM4.jpg (318 KB, 2022x1518) Image search: [Google]
HST-SM4.jpg
318 KB, 2022x1518
I'm normally a systems programmer, using C, and lately rust, but for a project I serendipitously became involved in, I need to port some programs over to the iOS platform using Swift, doing the full stack from logic to the user interface. I've been reading the Swift book by apple, and doing their tutorial, but I don't really feel comfortable with xcode. I usually do my programming in a text editor, or a lightweight IDE, nothing like Xcode. I also would like to get a better understanding of the Apple mindset. Any books out there for me?
>>
>>51289051
>How would I make the new stacks from within a member function
By calling the constructor for your stack class. Unless you're also calling your comparison function in the constructor there shouldn't be a problem.
>>
>>51289051
I haven't used C++ in a while but I was sure that you could instantiate classes in member functions. Just make sure not to leak memory while doing so or returning local addresses.
>>
How do I make this check if the file I'm reading from is empty in C++?
while (inputFile.get(curChar)) {
cout << curChar << endl;
}
>>
>>51289066
*** - 1+: #<FOREIGN-VARIABLE FOREIGN-ALLOCATE #x09475840> is not a NUMBER

Unfortunately none of the pointer types (c-pointer, c-ptr, c-array-ptr, ..) support arithmetic, and I can't see how to manually mod the internal state.
>>
I know fuck all about programming and want to get it into it. Should I start at codeacademy or try out khan academys code programs?
>>
File: 1446981142415.jpg (110 KB, 554x680) Image search: [Google]
1446981142415.jpg
110 KB, 554x680
I hate codeeval so much.
I finally figured out that fucking matrix rotation challenge and I only get PARTIAL score because their test data doesn't include a newline character for the final test case.
So now I have to rewrite my neatly written solution to work around their shitty site.
>>
>>51289157
>figured out the challenge
The one like three people told you how to do and three other literally gave you code for?

And you fucked it up?
>>
>>51289044
some things require state fgt
>>
>>51289184
nobody gave me code, what are you talking about?
>>
File: uswHPUA.png (839 KB, 3104x1742) Image search: [Google]
uswHPUA.png
839 KB, 3104x1742
>>51289086
Honestly, coming from someone who jumped right into Xcode, you probably don't need a book. Just get in there and fiddle around.
>>
>>51289145
Sounds like shit, sorry for your loss.

http://www.clisp.org/impnotes/dffi.html#offset
This sounds like it could work, albeit painfully.
>>
>>51289145
Gah, fuck this library. The smallest change to the function signatures (which you have to hack around to get anything working) garbles the fucking C and it segfaults.
>>
>>51289040
>But I become more error prone that way.
the IDE literally points out errors you make
>Also my school requires us to hand write code for tests.
that's school. real life doesn't require it except if you're sketching out an algorithm or something, then it helps to be able to draw things and not just type text.
>>
>>51288804
C++ has a header for run-time type information as part of the standard library. A lot of people have done hacks with macros, or neat template functions to give them more.
>>
>>51289253
Fuck it, I'm just gonna open a socket and pass messages that way.
>>
>>51288182
You could make the second one a generator by switching it from a list comprehension to a generator one using parens.

But still, the first is probably better.
>>
>>51289111
please desu
>>
File: 1439061543070.jpg (162 KB, 1920x1080) Image search: [Google]
1439061543070.jpg
162 KB, 1920x1080
>>51288118
just did the first benchmark!


my lib linkedlist_addFirst()
43.223027 ms
21.461703 ms
20.867560 ms
20.966317 ms
20.788709 ms
20.680595 ms
21.130793 ms
20.797300 ms
20.777395 ms
21.079600 ms


libstdc++ std::list::push_front();
48.837830 ms
25.327174 ms
25.541867 ms
25.289878 ms
25.545639 ms
25.412241 ms
25.447790 ms
25.507226 ms
25.460571 ms
25.535093 ms
>>
>>51289111
If the first get() has succeeded, the file has content and thus is not empty
If the first get() has failed and you have already verified its existence, then the file has no content and thus is empty
>>
>>51289394
thank you
>>
>>51289155
>>51289155
Any help guys?
>>
>>51289577
http://ddili.org/ders/d.en/index.html
>>
>>51289577
http://sarabander.github.io/sicp/
>>
>Want to make a slot machine without looking up other code
>Think it'll be simple
>Have no idea where to start

Well alright then.
>>
>>51289766
Maybe an array of values for the possible symbols on the slots, randomly select however many of those values for each of the slots, and if those random choices match any of the winning combinations, you win money
>>
File: syd_consider_the_following.jpg (13 KB, 200x200) Image search: [Google]
syd_consider_the_following.jpg
13 KB, 200x200
Does anyone here know anything about machine learning?

One of the tutorials for TensorFlow describes how to train a neural network for machine translation, and I've been wondering if it's feasible to train a Japanese-to-English one using things like video game scripts and anime subs.
>>
>>51290150
it's gonna be at least as shitty as google translate. translating natural languages is hard
>>
File: cat_contemplating_suicide.jpg (53 KB, 495x490) Image search: [Google]
cat_contemplating_suicide.jpg
53 KB, 495x490
>working on bio homework

I wish I was programming
>>
>>51290209
Make a program to finish your bio
>>
File: SadCat.jpg (69 KB, 505x490) Image search: [Google]
SadCat.jpg
69 KB, 505x490
>>51290209

lel

what uni you go to?
>>
>>51289385
wow must be super hard to beat a naive linked list implementation, maybe you should go back to 1967 and write a paper
>>
>>51290150
machine learning is the meme to end all memes.

It's like game programmers who call pathing 'AI'

It's primitive bullshit with a fancy name so neckbeards can circle jerk each other into thinking their smart.

Oooh nearest neighbor in high dimensions and a directed acyclical graph, hot shit, I'm doing 'machine learning' and 'neural networks'
>>
>>51290209
>This guy is literally a highschooler

Now it all makes sense
>>
I've been checking out Lua for use with Love2D.

I... kind of hate this language. I mean:

>Variables are global by default
>No real arrays
>Biggest data structure is an associative map that returns "nil" if you misspell something as opposed to throwing an error
>Explicit self in methods
>Methods are called with
instance:method()



I feel like I should be writing this in a functional style, but functional programming without a good type system is kind of terrible. Well, Lisp I guess, but Lisp has other things going for it.

Fuck.
>>
File: common sense.jpg (95 KB, 1680x1050) Image search: [Google]
common sense.jpg
95 KB, 1680x1050
I decided to learn C. What is the best online resource for learning?
>>
>>51290330
>>>/vg/agdg
>>>/trash/
>>
How hard would it be to write a lisp compiler using LLVM as the backend? Worthwhile exercise?
>>
>>51290265
sorry to disappoint you (.__. )
>>
>>51290344
I'm not complaining there because that place is full of artists who know very little about programming.

I didn't want to get responses that said shit like "Duh, variables are most useful when global, so you can access them anywhere. Why limit yourself?"
>>
>>51290344
Trash was such a great idea.
>>
>>51290337
http://www.cplusplus.com/doc/tutorial/
>>
>>51290367
>unironically wanting to use love2d
>implying you're not an artist who knows very little about programming
>>
>>51289385
It's shit.
Kill yourself.
>>
>>51290390
>its not REAL programming if it isn't C++ and it isn't a pain in the ass
>>
>>51290409
>>51242573
>>
File: ௵.jpg (21 KB, 326x298) Image search: [Google]
௵.jpg
21 KB, 326x298
>>51290385
C is not the same thing as C++
>>
Did Fallout 4 devs literally forget what delta time was?
>>
>>51290390
I'm not an artist. Not by any means. I can't draw a goddamn rectangle.

I'm not an expert programmer or anything, but I would consider programming my primary hobby.

Love2D was recommended to me by a friend. The more I use it the more I hate it. I think it's time to shop for another engine.

Game Programming so far has been pretty fucking terrible.
>>
>>51290417
You're complaining about it being a pain in the ass, douche.
>>
>>51290437
The guy who posted >>51290417 isn't me.

I'd rather use C++ than Lua, honestly. Lua is just sort of terrible.
>>
>>51290330
>>Variables are global by default
No? It's not difficult to declare them with "local"
I'm sorry not every language is python? Did you know that python is one of the few languages with implicit variable declarations?

>>No real arrays
This is an issue sometimes. It actually makes appending very easy:
list[#list] = val

But length counting operations in O(n) is unfortunate.

>>Biggest data structure is an associative map that returns "nil" if you misspell something as opposed to throwing an error
Ok, yes.

>>Explicit self in methods
>>Methods are called with instance:method()
Have you seen the alternative (JavaScript's "this")? It's fucking terrible.

>>51290437
I'm actually >>51290417

Lua's strongpoint is it's simplicity. If you want a huge fucking language then by all means use C++. Lua and Love2D is meant for prototyping. I believe you have "missed the point"
>>
>>51290413
why
>>
Guys what's the point of generics? Can't you just cast your data to the proper type when you call the function?
>>
>>51290458
Slow as fuck.
>>
>>51290449
I always wanted to learn Lua for Gmod.

Was never sure if it would be worth it though.
>>
>>51290431
Maybe you're shit at it and you'll always be shit at it.

Love2D is as easy as it comes. How much easier do you think it's going to get?
>>
>>51290472
Type erasure is a kind of generics, it just sucks for debugging and detecting errors at compile time.
>>
>>51290458
Don't listen to him. You're beautiful.
But honestly linked lists in C are not very complex, easier to reimplement than to use a library for because of lack of generics, and not as elegant as when expressed in Lisp or ML-like languages (see: pattern matching)

>>51290472
Because that's unsafe (casting wrong results in shitty results. Why not just have the compiler know that your program works rather than leaving it up to chance)
It's unclear (why do I have so many objects without a type? Why can't they just have a clear type?)
The alternative isn't better than actually having generics, and they're not very complicated and readily available in tons of languages.
>>
>>51289385
>unironically using a linked list in 2015
Dude it's literally faster to iterate over millions of entries on modern CPUs than it is to chase pointers.
>>
>>51290517
>ppl only uz a linkd list fur speed durp durp

Just leave
>>
>>51290428
lel what's the issue?

imo the game overall looked really shitty from a technical standpoint on conan o'brien, like we haven't made any progress in 8+ years
>>
>>51290472
>hey guys, can't I just like cast a string to an int?
>>
>>51290517
>Searching random entries is faster than an ordered linked list
>>
>>51290427
im memeing so hard right now you dont even know
>>
>>51290540
Wtf are you talking about? If it's faster to just store the data sequentially then you can overwrite the array whenever you need to add, remove entries, eliminating the only case where linked lists are useful
>>
>>51290561
>tfw it actually is if you look at the benchmarks, assuming you iterate through them
>>
>>51290573
"the benchmarks", you say?

Someone should message Mr Unix and tell him to stop using linked lists in buffer caches.
>>
>>51290564
Recursion? Trees?
>>
>>51290559
Strings are shit so obviously that doesn't work. I come from a C background so fuck off. I'm talking about designing your data in a way which lets you reuse functions easily. If your structs are similar it's not hard.
>>
>>51290564
Of course it's faster to search sequential data, but you can't pre allocate memory for a structure of unknown size.
>>
>>51290590
You can trivially implement those with static arrays.
>>
>>51290612
https://en.wikipedia.org/wiki/Parent_pointer_tree
>>
>>51290455
I'd rather have "local" be the default and "global" be the annotation. In any well-designed program you're going to try to minimize "local" variables as much as possible.

I like the Ruby approach (use Sigils for scope, so var is local, @var is instance, and $var is global) the best, but Python's is better than Luas.

>But length counting operations in O(n) is unfortunate.

Finding the length of an array is O(n) and there's no way to get around it? What the fuck, are you serious?

I like languages where my types behave like types. I don't want to be able to do something akin to
t = {1, 2, 3}
t.oops = "LOL"


because t is supposed to be an array, and oops doesn't belong on my array. t.oops should throw an error because it makes no sense for an array to have a member called oops

>Have you seen the alternative (JavaScript's "this")? It's fucking terrible.

It is, which is why I also dislike JavaScript.

>>51290491
Love2D has an easy API, but I feel like I'm fighting the fucking language to do anything. It's not Love2D I'm complaining about, it's Lua.

I get that Lua is a simple language designed to be easy to JIT. That's fine. But I dislike a lot of the design decisions it had to make to do that.

For me, I think the biggest thing is table value access. I think that returning nil if a key isn't in a table is fine, but only if you have other data structures that don't have this behavior. I want to be able to create something where, if I type t.foo and t has no member foo, then it throws some kind of error and tells me that. This makes it a lot easier to reason about what's going on. Am I getting an error because I misspelled something, or because some value that should exist doesn't?

Even worse, foo will work even if foo was never declared.
>>
>>51290517
Not everything is millions of ints, sometimes you have larger structures/buffers of say a couple K (a page lets say), and then linked lists are faster.
>>
>>51290629
You should design me a language.
IMO it's a more interesting topic than game dev. Although that's probably because I gave up game dev because I can't draw and have nobody to draw for me.
>>
Figured out a good 2-stage structure for my parser.
1. It lexes the input string, while dealing with mixfix, into tokens that form s-expressions.
2. It parses the tokens into top level statements and type theory expressions.

So a string like:
_+_ : Int -> Int -> Int

gets lexed into something like:
(_:_ _+_ (_->_ Int (_->_ Int Int)))

which is then parsed into:
Decl "_+_" (Pi (Ref "Int") (Pi (Ref "Int") (Ref "Int")))


The actual type theory is more complex than that (for example, pi sets have dependent typing, linearity, and explicit closure), but that's the gist of it. The lexer deals with all the fixity and associativity declarations for custom mixfix, so the parser is vastly simplified.
>>
>>51290641
That's not a "linked list". You can just have an array of structs. It's only a linked list if each struct points to the next one.
>>
>>51290674
>That's not a "linked list"
Of course it is.
>You can just have an array of structs.
That would be too slow when you need to insert/remove entries in the middle.
>It's only a linked list if each struct points to the next one.
Yes?
>>
>>51290674
The fact that you don't understand shows that your opinion is probably not well informed...
He's saying that implementation that as a resizable array would be inefficient because resizing the buffer would require copying and moving very large amounts of data, while using linked lists would be more efficient (no copying).
>>
>>51290599
This is never a good excuse. You need to have some idea of the amount of data you're dealing with. You can't just throw your hands up in the air and say "Theoretically it scales to 16 Exabytes!" and be done with it.

You should know how much space you need, and allocate precisely that much, with code to reallocate in extraordinary circumstances. If it's a library, let the user manually set it. None of this, "oh well just throw it on the stack lol" bullshit.
>>
>>51290662
Language design is really complicated. I actually had an idea a while back where functions can have traits, which are kind of like additional types on top of their input and output types. So you can say a function is "threadsafe", then have a "spawn" function that makes a new thread and runs a given function, but only if that function is threadsafe, or something.

If I do my masters I'll do it in compiler design, I guess.
>>
>>51290717
>If I do my masters I'll do it in compiler design, I guess.
Isn't compiler design more like parsers and stuff? Not like the interesting function trait idea you were talking about
>>
>>51290738
I believe the course does involve language design and type theory as well.
>>
>>51290717
in C++ that's called const
>>
>>51290717
>I actually had an idea a while back where functions can have traits, which are kind of like additional types on top of their input and output types. So you can say a function is "threadsafe", then have a "spawn" function that makes a new thread and runs a given function, but only if that function is threadsafe, or something
Literally just pure (generally, referentially transparent) functional programming
>>
>>51290666
is the _ ... _ part equivalent to ( ... ) in Haskell/ML (as in declaring the operator) or does it declare _+_ as the actual name of the function?
>>
>>51290758
>>51290757
Clearly he was talking about the threadsafe thing being just one possible use of the traits?
>>
>>51290757
>>51290758
The idea would be that you can have multiple different traits, not just "threadsafe".

It's not a fully developed idea. I'm not a language designer.
>>
const int*const methodName(const int*const&) const;

well ain't that comprehensible...
>>
Hi /g/. Quick question here.

I'll be hosting a site, soon. Well, a "site". When the address is typed in the address bar, the visitor will see either a youtube video, a newspaper headline which is also a link to the article, or a work of art. Each refresh will bring something new.

How should I do this? A database which returns a random item (the content) from a directory? A text file with all links and a php script to read a random line? I don't know much about webdesign but I'd figure I'd ask here, being that, programming-wise, it isn't too much work but I don't know what will be most efficient.
>>
How would I go about inserting a newline at the end of a file if it's not already there?
This doesn't work.
void insert_newline(FILE *fp)
{
/* adds newline character to end of file */
fseek(fp, -7, SEEK_END);
char c = fgetc(fp);
if (c != '\n')
{
fputc('\n', fp);
}
rewind(fp);
}
>>
>>51290767
It's a mixfix declaration, like Agda.
So yes, it's sort of like how you declare infix operators in Haskell or ML-likes, but it's much more generic.

Some other examples of mixfix operators:
if_then_else_ : Bool -> Bool -> Bool
_?_:_ : Bool -> a -> a -> a
[_] : <insert scary dependent type here to turn nested pairs into a list>


>>51290781
>>51290817
If you go down the rabbit hole of type systems, you essentially get to what I'm designing my language around. It's based on dependent and linear type theories, which together can (as far as I can tell) make it possible to leverage the type checker to do pretty much any form of static verification, such as preventing concurrent writes to the same place in memory. However, there aren't "traits", just parameter types and a return type.
>>
>>51290897
Also I totally messed up the type for if_then_else_. It's actually the same as the ternary _?_:_, now that I think about it.
>>
>>51290874
FILE *file = fopen("file.txt", "a");
>>
>>51290911
/dpt/ is useless as usual
>>
>>51290288
Neural networks are kinda different, I mean just look at what AlexNet did in one year compared to the next best solution of Imagenet
>>
File: figure_1.png (215 KB, 1818x1008) Image search: [Google]
figure_1.png
215 KB, 1818x1008
Does anyone know of a good graphing library for python? matplotlib looks like ass.

Pic related
>>
>>51291115
Check out tensorflow.
>>
>>51291013
git gud
>>
File: 1446781214640.jpg (92 KB, 599x647) Image search: [Google]
1446781214640.jpg
92 KB, 599x647
>>51291137
I already figured it out.
"r+" so I don't have to reopen the file to actually read from it.
>>
File: C programming Bible.jpg (125 KB, 300x377) Image search: [Google]
C programming Bible.jpg
125 KB, 300x377
>>51290337
Buy the C bible
>>
File: cute.jpg (680 KB, 1920x1080) Image search: [Google]
cute.jpg
680 KB, 1920x1080
iterations

my lib
56.409669 ms
58.989173 ms
54.362099 ms
56.385992 ms
54.793618 ms
54.548834 ms
54.835987 ms
54.977351 ms
55.376800 ms
54.272866 ms
mean: 55.495239 ms


libstdc++
56.839247 ms
56.977600 ms
58.770138 ms
56.744318 ms
54.613580 ms
58.030960 ms
55.870630 ms
56.127946 ms
55.037547 ms
55.864274 ms
mean: 56.487624 ms


Told you guys: state of art.
>>
>>51290874
your code unchanged works fine on my machine (debian)

ins.c:
#include "studio.h"

void insert_newline(FILE *fp) {
fseek(fp, -7, SEEK_END);
char c = fgetc(fp);
if (c != '\n') {
fputc('\n', fp);
}
rewind(fp);
}

int main(int argc, char **argv){
FILE *fp;
fp = fopen("test.txt", "a");
insert_newline(fp);
fclose(fp);
return 0;
}


test
> gcc ins.c -o ins
> touch test
> cat test
> ./ins
> cat test

> echo it worked
>>
File: graph[1].gif (3 KB, 400x300) Image search: [Google]
graph[1].gif
3 KB, 400x300
>>51291136
I'm not sure that does what I want

All I'm aiming for is pic related, where nodes are posts, and edges signify one post quoted another. For example, my other pic was actually this thread.
>>
>>51291168
code ?
>>
>>51291171
Of course it's gonna work if the file is empty.
The one I posted clobbers the last 3 or 4 characters from a file.
Here's a fixed version.
void insert_newline(FILE *fp)
{
/* adds newline char to end of file if it doesn't exist */
int seek = sizeof(char);
fseek(fp, 0 - seek, SEEK_END);
char c = fgetc(fp);
if (c != '\n')
{
fseek(fp, 0, SEEK_END);
fputc('\n', fp);
}
rewind(fp);
}
>>
>>51290346
already been done several times.
>>
Is there an easy way to switch the selected item on a pair of combo boxes that have the same datasource? Standard C# Winforms.

I have four combo boxes that share a datasource. Each combo box has to be unique; the idea is that changing one dropdown will change the value to the other one. I was thinking something with selectedindex?
>>
File: Screenshot_2015-11-11_00-00-13.png (50 KB, 1598x898) Image search: [Google]
Screenshot_2015-11-11_00-00-13.png
50 KB, 1598x898
>>51291194
Here's what I did desu
>>
>>51290428
>120hz
>game plays at double the speed
>bethesda confirmed for phoning it in
>>
>>51291260
why are you running loops until you hit EOF when you can just fseek to the end and fputc a newline character?
>>
>>51290428
>>51291261
It's part of their engine, skyrim got all kinds of fucked up when you changed settings
>>
>>51291332
I just assumed the problem in your original solution was with the fseek(), so I just cut that out entirely. You're right though.
Why not do
fseek(fp, -1, SEEK_END);

instead, since you already know a char is going to be one byte
>>
>>51291380
that doesn't sound portable.
Why not
fseek(fp, 0-sizeof(char), SEEK_END)
>>
>>51291260
>>51291194
It's probably correct to restore the file pointer's original offset.
 
#include <stdio.h>

void
insert_newline(FILE *fout) {
long start_offset = ftell(fout);
fseek(fout, -1, SEEK_END);
if (fgetc(fout) != '\n') {
fseek(fout, 0, SEEK_END);
fputc('\n', fout);
}
fseek(fout, start_offset, SEEK_SET);
}

int
main(int argc, const char **argv) {
if (argc < 2)
return 1;

const char *filename = argv[1];
insert_newline(fopen(filename, "a+"));
return 0;
}
>>
>>51291396
sizeof(char) is GUARANTEED to be 1 by the C standard.
>>
>>51291396
>that doesn't sound portable.
It actually is, which may seem ridiculous, but a char is an absolute synonym for byte in the C standard.

The number of bits (CHAR_BIT) is implementation defined, however.
>>
>>51291396
Also you could just do -sizeof(char).

ZOMG OPTIMIZED
>>
>>51291400
a+ already sets your seek position to the end for writing, there's no need to restore the original offset unless you're gonna keep using it.

>>51291430
wait, can you make a variable negative by adding a negative sign?
>>
>>51291454
>wait, can you make a variable negative by adding a negative sign?
wat
>>
>>51291457
seek = sizeof(char)
fseek(fp, -seek, SEEK_END);
>>
>>51291454
>wait, can you make a variable negative by adding a negative sign?
The unary negation operator.
>>
>>51291454
>a+ already sets your seek position to the end for writing,
High level functions are supposed to assume as little as possible. What if I have a file that I have open as r+ and I want to use insert_newline on it? Is the library programmer going to give me a hard time and make me set the seeks myself, or is his function going to work with as few side-effects and headaches as possible?

sizeof(char)
evaluates to 1, so your question is, can you do -(1) to make -1, and the answer is yes.
>>
>>51291478
Most shit isn't going to be library code. If it's safe to make assumptions, there us no reason to check them.
>>
>>51291502
You'll learn someday.
>>
>>51290306
>literally a highschooler

Wrong, nigger.
>>
there is some fucking C noob that has been asking retarded questions and spreading bullshit for a couple days...
>>
>>51291568
Who?
>>
is it a good idea to import 3d objects directly from blender to libgdx or should you just transfer them as pngs
>>
>>51291463
how can you not know about unary minus

tippity top kek

back to programming 101 for you

https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B
>>
>>51290874
> How would I go about inserting a newline at the end of a file if it's not already there?
Open the file in append mode, write a newline, close the file.

Probably not particularly relevant here, but opening a file in append mode and seeking to the end of the file aren't equivalent if multiple processes are writing to the same file. Append mode will always append, while seek-and-write has a race condition (i.e. something else may have written to the file between the seek and the write).
>>
>>51291588
is this real life??
>>
>>51291568
>Someones asking questions about programming in the Daily Programming Thread
>>
>>51291580
Me >:))))))
>>
>>51291596
fuck off you aspie
>>
>>51291611
why would it be a good idea not to import them directly

how does it make sense to transfer 3d models as pngs?
>>
>>51291594
I normally would do my best to avoid writing to one file with two processes so I don't know; is there really a race condition? I thought stdio was generally thread-safe and that unlocked_stdio has race conditions.
>>
>>51291624
>why would it be a good idea not to import them directly
because it's a fucking hassle and i only need a single shape

>how does it make sense to transfer 3d models as pngs?
you can render animations as pngs
>>
>>51291598
problem being, this guy seems to be truly retarded, yet he keeps asking retarded questions, posting "advanced" shit and blaming the compiler for his stupidity
>>
>>51291639
>you can render animations as pngs
well then it's mainly a question of whether you want/need the 3d model or if you just want sprites instead
>>
>>51291645
examples?

i smell new CS graduate memes
>>
>>51291625
Replying to myself, I read more about file locks and now I understand how they are implemented and why a separate process doesn't care about my process's file locks.
>>
>>51291652
see >>51291454 .

>>51291261
top kek
>>
>>51291651
do i want/need the 3d model?
>>
How do I set a Boolean to maybe?
>>
>>51291700
if you're using it to render it from many perspectives or whatever so you can't just keep pre-rendered sprites. or if it's some simple little animation you may as well just use a series of pngs
>>
>>51291709
>In most computer programming languages, a Boolean data type is a data type with only two possible values: true or false.
https://en.wikipedia.org/wiki/Boolean

you can set a Boolean object in java/C# to null though
>>
>>51291261
>these retards in charge of making multi-million dollar gaymes
>>
>>51291709
not many languages have maybe for Booleans

there's only one I know of: C+Equality
>>
>>51291735
>you can set a Boolean object in C# to null though
booleans in C# are a value type; they cannot be null.
maybe you were thinking of a
Nullable<bool>
? In C#, you can add optional null-ness to value types
>>
>>51291791
>>51291735
Sorry, I was just telling a joke. I thought it would make you laugh.
>>
>>51291709
RNG function that randomly returns true or false.
>>
>>51291115

plt.style.use('ggplot')
>>
>>51291810
>true or false
>maybe
pick half
>>
>>51291791
"Instead of Booleans we now have Boolean+, or bool+ for short, which has three states: true, false, and maybe. The number of states may go up as intersectionality of the moment calls for such a need."
heh
>>
hi /g/, I want to learn something new.. basically I am creating an app on Windows 10, and I want to serialize my data online..

So, should I use Microsoft SQL Server 2014 Express?
>>
This doesn't work, presumably because the string literals are all destroyed upon calling exec(). It should print "here's a test", but it prints garbage instead. What is the proper way to pass a char * to a child process?
#include <unistd.h>

int main() {
int pid = fork();
if (pid == 0)
execlp("/bin/echo", "here's a test", (char *)NULL);
else
printf("In parent with child %d\n", pid);
abort();
}
>>
>>51292116
Remember that argv[0] is typically the name of the program, so it's actually the second argument that should be your string to print.
>>
i've been using Catch for C++ unit testing so far but now i need to time individual functions which Catch doesn't support
id rather not write manually myself, is there a good framework for this?
>>
>>51292179
Yeah that fixes it. I thought the OS (or even exec itself) would handle that for me or something. Weird.
>>
So progress has been made. I just need one more bit of help. The following:
(ffi:def-call-out
mffi-identity
(:name "matrix_identity")
(:library "./libffi-matrix.so")
(:arguments (Ar int)
(Ac int))
(:return-type (c-ptr (c-array double-float (5 5)))
:malloc-free)
(:language :stdc))

(print (mffi-identity 5 5))


will correctly yield a 5x5 identity matrix. The problem is that on the line
(:return-type (c-ptr (c-array double-float (5 5)))

should plug in two variables instead of 5 and 5 and the ffi:def-call-out macro doesn't seem to like it when I try and backquote them in. How can I go about escaping/writing a new macro to do this?

http://www.clisp.org/impnotes/dffi.html
>>
How do i compile all my files that start with ex and end with .c (ex1 ex2 ex3 ex4)
Basically ex*.c
>>
>>51292308

Make a Makefile.
SRCS=ex*.c


Default should compile everything with gcc or whatever your system C compiler is, with no cflags. You can set any cflags or linker shit how you want in the Makefile as well.
>>
>>51292308
I'm assuming a lot here, but something like this is possible in bash:

# Assumes each source file is an independent program.
for f in ex*.c; do gcc -o ${f%%.c} ${f}; done
>>
File: Gin.Tama.full.1912378.jpg (845 KB, 800x1500) Image search: [Google]
Gin.Tama.full.1912378.jpg
845 KB, 800x1500
>>51291188
Not FOSS, sorry. Last time i opened my heart to dpt, you guys crushed me.
>>
>>51291168
>mean

Why? Are you using random inputs?
>>
>>51292434
>writes shit code
>stays shit because afraid of criticism

>>>/trash/
>>
File: fe.gif (973 KB, 500x322) Image search: [Google]
fe.gif
973 KB, 500x322
>>51292554
why shit code ?
>>
>>51292308
simply with gcc ex*.c
>>
>>51292272
On a related note:
(defmacro test-macro (x) `(print ,x))
(print (expandmacro '(test-macro 5)))
=> (PRINT 5)
(defparameter z 5)
(print (expandmacro '(test-macro z)))
=> (PRINT Z)

How can I reach absolute resolution of symbols?
>>
>>51292582
I think the catch is that each ex*.c represents a separate program, not a separate piece of a single program.
>>
>>51292605
http://www.cyberciti.biz/faq/bash-loop-over-file/
for f in *.c; do echo "Processing $f file.."; done
Thread replies: 255
Thread images: 35

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.