[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
/dpt/ - 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: 31
File: g_fullxfull-29942.jpg (108 KB, 1280x720) Image search: [Google]
g_fullxfull-29942.jpg
108 KB, 1280x720
old thread: >>53890674

What are you working on, /g/?
>>
File: 1420229460495.png (300 KB, 485x354) Image search: [Google]
1420229460495.png
300 KB, 485x354
Thank you for waiting for the bump limit and not posting a fag image.
>>
>>53896911
I am being supportive
>>
>>53896914
I know whats up
>>
How do I improve my fizzbuzz without modulo?
int i;
int three = 3;
int five = 5;
for (i = 0; i < 20; i++) {
if (!three && !five) {
printf("FizzBuzz\n");
three = 3;
five = 5;
} else if (!three) {
printf("Fizz\n");
three = 3;
} else if (!five) {
printf("Buzz\n");
five = 5;
} else {
printf("%d\n", i);
}
five--;
three--;
}


>>53896914
It has nothing to do with programming though so still a failure.
>>
>>53896934
>she
>implying there are girls on 4chan

>>53896888
Alright, well thanks, I guess. I just don't really know where to begin.
>>
>>53896931
What does the negation operator do to an int? (!five)

Is that a C thing?
>>
>>53896959
bitwise not
>>
>>53896959
Zero gets converted to one.
Any non-zero value gets converted to zero.

It basically just tests if it's zero.

>>53896966
bitwise not is ~
>>
>>53896957
>I just don't really know where to begin
Things you need to understand to do FizzBuzz:
* For loops
* Conditionals (how to use if(...))
* The modulo operator (What does 11%5 equal?)

If you're still having trouble, try to write out the first few numbers manually. Try to figure out whether each number is a Fizz, Buzz or FizzBuzz using just the modulo operator
>>
>>53896986
>for loops
Yes
>Conditionals
Yes
>Modulus
I never quite understood it. What is it supposed to be/do? I'm sorry if I sound retarded, I'm a massive newbie.
>>
>>53896996
Not him but iirc returns the remainder after division
>>
>>53896969
>Zero gets converted to one.
>Any non-zero value gets converted to zero.

>It basically just tests if it's zero.

So what is the negation operator there actually *doing*?

Why does it convert a non-zero to zero?
>>
>>53896996
https://msdn.microsoft.com/en-us/library/se0w9esz.aspx

20 Mod 5
is 0

20 Mod 15
is 5

20 Mod 3
is 2
>>
>>53897006
I'm testing for false, so when it is false the if statement becomes true. NOT makes true into false and vice versa.

https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Logical_operators
>>
>>53897026
But how does 13 evaluate to true?
>>
>>53897039
three is a variable name. It counts down and when it is zero the NOT makes it one, which is true.
>>
Reminder that if your FizzBuzz program contains "FizzBuzz" (case insensitive) as a string, you're doing it wrong.
>>
>>53897006
>So what is the negation operator there actually *doing*?
What I described. C's boolean logic isn't exactly the same as most other languages. 0 is false, non-zero is true. C didn't have a proper boolean type (it does now, but it still works this way), so all of the logic is done with integers.
>Why does it convert a non-zero to zero?
Converting true to false.
>>
>>53896996
Divides two numbers and returns the remainder, if `X % Y == 0` that means X is multiple of Y.
>>
>>53897051
>>53897017
>>53897001
So Modulus divides the numbers to a whole, then returns the remainder? When would that ever be important, to the point where it has its own operator in programming? I don't see it in real-world maths
>>
>>53897044
>>53897046
>0 is false, non-zero is true.
Disgusting.

I get it now, though. Thanks for the explanation.

I know C has a time and a place, but this is yet another reason why I won't seek out an opportunity to use it.
>>
>>53897045
Do you mean like this or some char array fuckery?

    int i;
int three = 3;
int five = 5;
for (i = 0; i < 20; i++) {
if (three && five) {
printf("%d", i);
}
if (!three) {
printf("Fizz");
three = 3;
}
if (!five) {
printf("Buzz");
five = 5;
}
five--;
three--;
printf("\n");
}
>>
>>53896931
Just want to make sure I understand this: three and five are decremented as the first few numbers are printed in the else; then the !three evaluates to true since three is 0 and is reset to three etc. So you are hitting all numbers divisible by five and three individually and naturally 15 when it is divisible by both. Happy I was able to get that lol
>>
>>53897075
>When would that ever be important
Figure it out on your own, given that you're trying to do FizzBuzz. Its the key to what you need to do

You are looking for numbers that are divisible by 3, 5 and 15. How can you use the modulo operator to help you?
>>
>>53897075
If value % 3 == 0 then value is divisible by 3 (Fizz)
>>
>>53897082
>Disgusting
What? You think 0 = false, 1 = true and 2..INT_MAX,-1..INT_MIN = undefined is better?
In C, everything is an integer, and it doesn't hide that fact.
>>
>>53897085
I mean anyone who has separate code to print "FizzBuzz" is doing it wrong.

If they use the literal "FizzBuzz" to generate substrings it's not wrong.
>>
>>53897075
is this nigga serious
>>
>>53897075
Frankly, it isn't used that often, but it is necessary in some situations.

Basically any time you want to do something on every xth iteration, or if you need to check divisibility for an algorithm.
>>
>>53897082
The logic of C is perfectly fine. What languages are you used to?
>>
>>53897082
Except if you ever do any machine coding you'll see why this makes total sense and why limiting the scope of zero and one does not.
>>
>>53897121
or if you have a repetitive pattern like if you have rows, or if your algorithm has "rollover"/clock arithmetic
>>
>>53897110
Just learned about this in my CompSci class. Professor sold me on efficiency and seems like he knows his shit.
>>
>>53897141
Rollover clock arithmetic? Can you explain real quick?
>>
>>53897138
>>53897142
doesn't mean you can't abstract it behind a boolean type, especially in a higher-level language
>>
>>53897045
Is there a proof for why if a number has two factors, A and B that (A*B) is also a factor of that number? Feels like it should be obvious but I'm dumber than a rock
>>
>>53897110
>>53897129
>>53897138
I'm not saying it isn't practical, or even 'bad' necessarily, it's just that I prefer nearly everything to be explicit.

I understand the implicit conversion of a bit representation of 0 or 1, but if I try to evaluate 43 as a boolean, I would prefer my language to fuss at me, in case I was making a mistake.
>>
>>53897155
for example in pacman when you move past the edge of the map and you end up on the opposite side

things like that
>>
>>53897158
But why would you want to?
>>
>>53897168
Yeah but you can have a languages with warnings that still allows compilations.

Personally I hate languages which treat me as an idiot and decide to baby me.
>>
>>53897158
What does that even mean? How else would you represent True/False in x86?
>>
>>53897168
What languages?
>>
>>53897168
Again, everything in C is an integer. I have never run into any problems with 'accidentally' evaluating an integer as a boolean.
If you're really fussed about it, use the _Bool/bool type, which will automatically convert any non-zero value to 1. The compiler won't type check it for you though.
>>
>>53897174
>>53897185
type safety as a language feature to avoid making mistakes. like if(foo != 0) instead of just if(foo), the compiler can still optimize it to the same thing
>>
>>53896931
int th, fv, i;

for (i = th = fv; i <= 100; ++i, ++th, ++fv) {
if (th == 3) {
printf("Fizz");
th = 0;
}
if (fv == 5) {
printf("Buzz");
fv = 0;
}
if (th && fv)
printf("%d", i);

printf("\n");
}

>>
>>53897208
This would always print integers wouldn't it?
>>
>>53897208
Yikes.

for (i = th = fv = 1; ...
>>
File: sw.png (17 KB, 341x248) Image search: [Google]
sw.png
17 KB, 341x248
>>53897160
bamp
>>
>>53897138
If I was asked to write machine code in any sort of professional environment, I'd find another job. This is why we have high level languages.
>>
>>53897208
Pretty nice 2bfrank witchya
>>
>>53897230
Jobs that requires doing this would be extremely high paying and crucial to the development of hardware technology.
>>
>>53897242
They're high paying because nobody in their right mind wants to do them.
>>
>>53897160
I don't even understand what you've written.

If a number 'n' has two factors A and B. then A * B is n because that's what it means to be factors...
>>
>>53897260
I would. I just don't know how to become qualified for them.
>>
>>53897230
And if I were your boss I would say good fucking riddance and have a flock of eager respectful Indians to replace you before you were out the door.
>>
>>53897230
I'm not asking you to write machine code. I'm saying to think about the fundamental architecture of the computer to decide what makes sense.
>>
>>53897261
A number can have more than two factors.
>>53897160
You remember crossing out numbers in fractions, right? Well, if n = a*b*c, and you put (a*b*c / a*b), the a and b cancel out and you're left with c.
>>
>>53897261
No, I never said that A and B are factor PAIRS. For example, 2 and 5 are both factors of 100. But 25 and 4 is a factor PAIR of 100 because 25*4=100.

What I want a proof of is that given any two factors (*not* factor pairs), the product of those factors is also a factor.

So for 2,5 being factors of 100, 2*5=10 is also a factor.
>>
>>53897307
>Well, if n = a*b*c, and you put (a*b*c / a*b), the a and b cancel out and you're left with c.

I don't get it
>>
>>53897308
24, factors are 3 and 6. 18 is not a factor of 24
>>
File: Untitled.png (181 KB, 1920x1080) Image search: [Google]
Untitled.png
181 KB, 1920x1080
What the fuck
Did anyone else just get a new 4chan layout?
>>
>>53897283
I understand what you're saying. But my point is that, at the high level, what happens at the machine level is largely irrelevant. What matters is what is easier to read or maintain, and IMO flag=true is more clear than flag=1.
>>
File: x.png (15 KB, 710x79) Image search: [Google]
x.png
15 KB, 710x79
>>53897361
okay nvm im retarded
what the fuck though
>>
>>53897399
>discord
No thanks
>>
>>53897386
So isn't that just called Lowest Common Multiple?
>>
>>53897378
C has a boolean type, and 'true' and 'false' are defined as 1 and 0 respectively.
So
bool my_flag = true;
is perfectly valid.

Also, boolean logic is hardly "high level". In fact, I wouldn't call it high level at all. I can represent booleans by driving a high voltage (or not) on a wire.
>>
>>53897308
prime factors are what you're looking for

try proofwiki.org
>>
>>53897378
I guess it's because people don't understand how computers work. My point is that I don't think true having to equal one is more clear than it being non zero. I think that is less clear because I understand how a computer works and I assume that the language does not make needless abstractions.

Basically I'm saying what you think is my clear is only because of your experience rather than any logical basis.
>>
>>53897361
that's le epic april fjewls gjewgle+ meme layout
>>
>>53897438
I went back a few threads and I got this. I wasn't on 4chan during April Fool's - did they switch the layout?
>>
What's with the entry level /dpt/?
>>
Sup /g/angstas.

How does babby parse HTML text in Java? I can successfully read the URL contents, but can't select specific strings I'd like to view.
>>
Why doesn't this general have a chat group?
>>
File: z3UnzM7.webm (2 MB, 640x640) Image search: [Google]
z3UnzM7.webm
2 MB, 640x640
Ask your much beloved programming literate anything (IAMA)

>>53896902
>What are you working on, /g/?
Nothing at the moment but found this https://github.com/chrissimpkins/codeface

>>53897110
>>53897129
In C, if( true == n ) and if ( n ) doesn't have the same semantics. Java fixed that.

>>53897138
Please explain. Many ISA are actually using a status flag (0 or 1) for conditional instructions.

>>53897416
C Boolean type is ruined by type promotion rules.
>>
>>53897530
>>>/g/wdg/
This is a more suited general for your question.
>>
Working on a Hangman program
>>
>>53897553
>C Boolean type is ruined by type promotion rules.
How? All it does is allow you to add booleans to other integer types, which is actually a good thing.
ANYTHING cast/assigned to a bool will automatically be converted to 0 or 1.
>>
>>53897553
What would a coder code if a coder could code the meaning of life?
>>
>>53897555
I'm trying to parse HTML in Java, though.
>>
>>53897668
Just search for some library. There are probably dozens of them available.
Parsing HTML yourself is hard as balls, because it's not necessarily well-formed. Maybe if it was XHTML, it wouldn't be so bad.
>>
>>53897553
Recommend to me a medium sized project preferably in the C programming language.
>>
>>53897479
yes
>>
>>53897640
answer = 42
def everything():
print("The meaning of life is %s" % answer)

everything()
>>
File: we_are_shiba.png (667 KB, 640x640) Image search: [Google]
we_are_shiba.png
667 KB, 640x640
>>53897596
it's shit because you can then use all operators on booleans. for example, something like
(true + true) & true
returns false.

>>53897640
here >>53890000

>>53897763
screensaver using opengl/vulkan
>>
Guys post progress of your programming application what you are working on
>>
>>53897871
Sounds hard considering my maths is very lacking. Guess it's time to learn linear algebra.
>>
>>53897855
Use new-style formatting kid.
answer = 42
def everything():
print("The meaning of life is {}".format(answer))

everything()


Seriously tho, formatting apis are always interesting, particularly knowing that %d-%s-%f make the most sense in C, where the format sequence has to carry type information, and that yet python and go use such legacy percent-style format specifiers... Also human vs reader vs eval representation...
>>
File: such_literacy.jpg (103 KB, 720x960) Image search: [Google]
such_literacy.jpg
103 KB, 720x960
>>53897915
>Guess it's time to learn linear algebra

http://immersivemath.com/ila/index.html
>>
>>53897883
Nothing to post desu, but here it is - it's a Hangman program I'm working on.
Imports System.Threading
Module Module1

Sub Main()

Console.WriteLine("Hangman v1.0")
Console.WriteLine("P. Danys 2016, All Rights Reserved")
Console.WriteLine()

Dim wordLibrary(9) As String
Dim alphabet(25) As Char
Dim guessPool() As String 'Stores all letters guessed
Dim gameWord As String 'The word that will be used in the game which the user guesses
Dim guessNo As Integer 'Stores Number of tries before the game is over
'If the counter reaches 11, the game is over
Dim rndWord As Integer 'Random integer used to select a word for the game
Dim spaceLength As Integer 'The number of spaces that are generated for the word
Dim guess As Char 'Variable used to store the guess


'Array of words that can be selected for the game
wordLibrary(0) = "example"
wordLibrary(1) = "book"
wordLibrary(2) = "quench"
wordLibrary(3) = "onion"
wordLibrary(4) = "damp"
wordLibrary(5) = "cheesecake"
wordLibrary(6) = "supernova"
wordLibrary(7) = "pomegranate"
wordLibrary(8) = "rucksack"
wordLibrary(9) = "watermelon"


Randomize()
rndWord = Int(Rnd() * 9) + 1 'Auto-generates a number between 1-10

gameWord = wordLibrary(rndWord) 'Picks a random word from the array

spaceLength = gameWord.Length
Console.WriteLine(spaceLength)


Console.WriteLine(gameWord)
Console.WriteLine()

For i = 0 To spaceLength
Console.Write("_" & " ")
Next
Console.WriteLine()
Console.WriteLine()

Do Until guessNo = 12

guess = Console.ReadLine()
Console.WriteLine(guess)

Console.WriteLine(12 Mod 5)

Loop


End Sub

End Module
>>
>>53897998
Pretty good you need to implement a GUI afterwards
>>
>>53897998
>>53898022
Forgot to mention, this program is nowhere near complete, so don't expect to make sense of it. The modulus line was me testing Modulae in VB; it's irrelevant to the program.
>>
>>53897871
(true + true) & true

Is there any specific case where it would bite you in the as tho? Accidentally doing integer operations on boolean sources and not seeing the error quickly when debugging? OTOH you can do some neat tricks with
true == 1
...
>>
>>53898022
>GUI
I could try. At best, you'd get a console interface desu; I'm nowhere near good enough to make a GUI
>>
>>53897218
No, to print the integer neither fv or th has to be non zero, and if fizz/buzz atleast one of them will be zero
>>
>>53898051
Oh, very clever.
>>
>>53897208
>unmaintainable
0/10 would not hire
>>
>>53896902
Learning python as fast as possible for a job interview at a major tech company. I only need to know basics because it's a job as a TTS technician. So currently working on learnpythonthehardway dot org
>>
>>53898045
Making GUIs is trivial with .NET languages.

You could do a WinForms GUI very easily.

Instead of
Console.WriteLine("Hangman v1.0");

You'd create a label with the editor and just do
lblTitle.Text = "Hangman v1.0";
>>
>>53897208
int th, fv, i;

for (i = th = fv = 1; i <= 100; ++i, ++th, ++fv) {
if (th == 3)
printf("Fizz"), th = 0;
if (fv == 5)
printf("Buzz"), fv = 0;
if (th && fv)
printf("%d", i);

printf("\n");
}


How badly am I messed up and unemployable if I like using tricks to avoid putting braces after ifs, /g/?
>>
>>53898032
I am aware but still progress is good progress

>>53898045
GUIs are very easy to make they just require 50 lines of code for everything and are very verbose

>Tfw I would grab a pizza with all you guys while we program

I wonder if there has ever been a /dpt/ meet up where we programmed together in person
>>
>>53898094
>I like using tricks to avoid putting braces after ifs
I would crucify one of my employees if they pulled this shit.

Even if it's a one-liner, you ALWAYS use containing braces.
>>
>>53897351
>>53897308
>>53897261
>>53897307
>>53897341
/Daily basic math general/
>>
>>53898092
I'm more than familiar with forms; I know how they work.

It feels kindy cheaty desu, and it would make for visualising the actual hangman difficult, ascii art aside. Therefore, what can be done in a form can be done in a console, making forms redundant AND bad practice.

Why do only .NET languages have forms?

>>53898119
There's a Discord - we could chat on that while programming
https://discord.gg/0vvLlMvfsNim00y8
It's got voice channels, PMs, text rooms, the whole nine yards. You don't have to sign up for an account to use it, it's supported on mobile, browser and client and it's free.
I don't understand why people here don't use it.

If the next person who makes the thread could include the invite link in the OP, that would be great.
>>
>>53898094
One problem your logic is wrong you want to check both if the number is divisible by 3 and 5 first because say what if you get a number that is by both but you have checking condition for 3 which will be true but when it is both.
>>
>>53898119
>Golang meme
To me, C was designed that way just as purposely as Go was designed to force braces but permit omitting parentheses. What shitty language do you use, whose features you have to actively avoid using?
>>
>>53898094
What the fuck are those obscure variables? The structure looks nice, but it's hard to maintain.
>>
File: 1443878595513s.jpg (5 KB, 125x125) Image search: [Google]
1443878595513s.jpg
5 KB, 125x125
>>53898148
reread this code and OP's (>>53897208), you're dead wrong. It's true that the error exists, but in this case it wasn't commited.
>>
>>53898161
It is wrong he doesn't have the first FizzBuzz case
>>
>>53898116
>I wonder if there has ever been a /dpt/ meet up where we programmed together in person

There'd be one dude walking around just screaming KILL YOURSELF at everyone.

Low-level fags would be circle jerking about milliseconds of performance.

Haskell, D, and other meme lang fags would be walking around just being fucking smug about everything without actually contributing.

.NET fags would actually probably get something done, with F# fags writing functional libraries to do data manipulation and C# fags doing the GUI logic.

Python fags would be showing off trivial 20-line scripts to rename all the folders in a directory.

Anyone else?
>>
>>53898190
This would be so funny to see
>>
>>53897308
Simple counter-example:
15 is a factor of 30, 5 is a factor of 30, but 15*5 != 30.
>>
>>53898150
I use C#, and while you can easily write one-liner IF statements, you generally shouldn't unless it's a trivial ternary operator.

If someone needs to add an additional statement to that command later, they have to re-write that segment of code.

Plus, readability.
>>
Join the official /dpt/ chat room

https://discordapp.com/channels/167259178375708672/167259178375708672
>>
>>53898156
th and fv are three and five, they evolved that way over this thread and last one. For the rest, maintainability is a meme concept. Code should be used to exchage ideas, period. If your idea becomes different, write a different code.
>>
File: mpvchap.png (172 KB, 648x399) Image search: [Google]
mpvchap.png
172 KB, 648x399
I'm improving mpv's OSC. But I don't know where would be best to show chapter title.
>>
>>53898147
>Why do only .NET languages have forms?
You mean literally the
System.Windows.Forms
.NET Framework Class library?
>>
>>53898243
>maintainability is a meme concept
/dpt/, everyone.

Welcome to dev hell.
>>
>>53898243
>maintainability is a meme concept
>>
>>53898236
Makes sense, but in that case, Python's model of semantic indentation or most Lisps' implicit progns are nicer tho. I admit I'm not a hardcore fan of brace languages.
>>
>>53898242
Don't use that to join the channel, use this invite link: https://discord.gg/0vvLlMvfsNim00y8
It's timeless and enables you to join, as opposed to just viewing the channel.

>>53898259
I suppose, yes.
>>
>>53898271
This is why the majority of programmers here don't write clean easy code to read instead they try to put everything on one line of code

Also, good Object Oriented Programming makes code very maintainable and very easy to read once you understand proper design patterns in Java
>>
>>53898242
wtf is that ?
>>
File: interject.jpg (105 KB, 1280x720) Image search: [Google]
interject.jpg
105 KB, 1280x720
>>53898271
/dpt/ regulars aren't Pajeet "devs", we are literate programmers and programming literates with a frenzy for discussing what constructs provide the most elegance to our ideas. Enterpriseâ„¢ is a place where you are made afraid to be intelligent, it's dangerous nonsense.
>>
>>53898301
>good Object Oriented Programming makes code very maintainable and very easy to read once you understand proper design patterns
0/10
>>
>>53898324
As an Enterprise Java programmer I agree Objects are the best
>>
>>53898309
It's a Discord chat for this general.
The idea is to be able to communicate in real time, share ideas, shitpost, discuss programs, advice etc.

Like this thread but faster and in real time
>>
>>53898355
it want me to register... are the conversations recorded then sent to the nsa ?
>>
I'm finally working on an RSS downloader to pick up the new madokami RSS feeds. Problem is, madokami uploads are disorganized as fuck -- sometimes there are big multi-chapter packs, sometimes there are multiple uploads of the same chapter, omakes, etc etc and it's all hard to parse.
Example:
     <item>
<title>Boku no Hero Academia Ch.084.005 Tsuyu Special [KissManga].zip</title>
<link>...</link>
<enclosure url="..." type="application/zip" length="2027905" />
<guid>...</guid>
<pubDate>Tue, 29 Mar 16 19:40:02 +0000</pubDate>
</item>
<item>
<title>Boku no Hero Academia Ch.085 So Full of Fools [KissManga].zip</title>
<link>...</link>
<enclosure url="..." type="application/zip" length="8801520" />
<guid>...</guid>
<pubDate>Tue, 05 Apr 16 19:43:35 +0000</pubDate>
</item>
<item>
<title>My Hero Academia - 083 - Defeat [MangaStream.com].zip</title>
<link>...</link>
<enclosure url="..." type="application/zip" length="6203116" />
<guid>...</guid>
<pubDate>Thu, 17 Mar 16 20:42:58 +0000</pubDate>
</item>
<item>
<title>My Hero Academia - 085 - Idiots All Around [MangaStream.com].zip</title>
<link>...</link>
<enclosure url="..." type="application/zip" length="7708819" />
<guid>...</guid>
<pubDate>Fri, 01 Apr 16 20:42:39 +0000</pubDate>
</item>
<item>
<title>My Hero Academia - Omake Special - My Hero Academia Smash [MangaStream.com].zip</title>
<link>...</link>
<enclosure url="..." type="application/zip" length="2100975" />
<guid>...</guid>
<pubDate>Fri, 01 Apr 16 20:42:36 +0000</pubDate>
</item>

Ideally all this would feed into an auto-downloader which just saves a single copy of the latest chapter and ignores the other versions, which I'm sticking on my raspi server.

Anyone ideas on how to parse title names? I'm thinking of regexing anything that looks like a number
>>
>>53898367
Haha no silly no one here is being monitored for any reason at all
>>
>>53898367
There's no registration required; you can use throwaway accounts with the option to register later. All you need to provide is a username/handle to go by in the chat

>record conversations and sent to the NSA
ofc :^)
>implying they aren't already
>>
>>53898038
>OTOH you can do some neat tricks with true == 1
not anything you can't do with (foo ? 1 : 0)
>>
>>53898396
>(foo ? 1 : 0)
!!foo
>>
>>53898393
good one shlomo
>>
>>53898355
Get the fuck out of here with this gimmicky discord garbage
>>
Python pleb here.
I have a list of names with corresponding values, which are very heterogeneous. Some names are short (p53, KSR), some are longer and more complex (PLC-epsilon, gonadorelin diacetate). I need to construct variables from these names, which contain their value (which can be 1 or 0).

What I want is a list of variables and values that looks like

p53 = 1
Mdm2 = 0
p21 = 0
Ras-GTP = 0
Ras-GDP = 1
IKK = 1


And so on. Which is the most efficient way to do this? Dictionaries?
>>
>>53898414
plain old foo in my case where foo is already a boolean.
>>
>>53898414
"To a C programmer strong typing means pressing the keys harder."
>>
File: le hands.png (24 KB, 386x306) Image search: [Google]
le hands.png
24 KB, 386x306
>>53898417
>>
File: OJmnB.jpg (224 KB, 1600x1200) Image search: [Google]
OJmnB.jpg
224 KB, 1600x1200
>>
Is C good to learn on Windows or only Linux/BSD/Mac? I see thta most windows software is written in C++ for some reason.
>>
>>53898431
>arbitrary mapping from arbitrary strings to arbitrary numbers
Yes, why not?

Except if you only really care about p53,Ras-GDP and IKK and can consider everything else as 0, in which case go for a set, but it's not as extensible. (Just me trying to be too clever, ;^) >>53898324)
>>
>>53898431
That's what a dictionary is for, yeah
{
'p53':1,
'Mdm2':0,
'p21':0
}


Though if you're dealing with a huge list it might be more efficient to just make a set of all things that have values 1 (or 0) and just test them by using 'in'

thingsWithValue1 = set(['p53','Ras-GDP','IKK'])
'p53' in thingsWithValue1
True
'p21' in thingsWithValue1
False
>>
>>53898462
Hey feds, came to look at my child pornography collection? :^)
>>
>>53896931
Clever.
>>
>>53898479
>Yes, why not?
Just wondering if there's some way of doing this that I haven't considered. MD-PhD newb dabbling in bioinformatics and programming here.
>>
>>53896931
pre-increment you nigger
>>
>>53898544
>Just wondering
I guessed. Still, as >>53898496 put it, that's what a dictionary is for ;^)
>>
>>53898548
If the compiler doesn't fix that it's probably meant to bootstrap a better compiler.
>>
>>53898496
What if we consider that I'd want each variable (p53, Mdm2, etc) to refer to a function? If I have a small set of functions (about 4) and each variable is supposed to point to that function, would it be possible to get something like the following from a text file (given that the text file contains info on which function maps to which variable)?

p53 = funcA()
Mdm2 = funcB()
p21 = funcC()
PIP3 = funcB()
>>
>>53898544
according to
http://stackoverflow.com/questions/3949310/how-is-set-implemented
The two methods are basically the same internally but the set method is a little more optimized.
Still, if you expect that you could ever have a reason to have anything except a 1 or a 0 as a value,
or if you want a nice big list in your source code so you can ctrl+f values to easily see if they're 1 or 0,
use a dict
>>
>>53896902
Thank you for using an anime image.
>>
>>53898607
>Still, if you expect that you could ever have a reason to have anything except a 1 or a 0 as a value
No, the only values will be 1 and 0. I will have about six thousand names I want to map to their values (or functions: >>53898604 ) though.
>>
>>53898619
RRRRREEEEEEEEEEEEEEEEEEE
>>
>>53898604
Yeah, python functions are also objects. In this case you'd use a dict
myVar = {
'p53': funcA,
'Mdm2': funcB,
'p21': funcC,
'PIP3': funcB
}

def funcA():
print('A')

def funcB():
print('B')

def funcC():
print('C')

will map the function to each var.
Then you can do cool shit like
myVar['p53']()
A

myVar['Mdm2']()
B


It's kinda cool like that
>>
>>53897075
are you fucking kidding me, you can't think of a single reason you would want to know the remainder of something

get out of /dpt/ dogg this is not for you
>>
Hi guys I want to make an Android app but I am scared of all the long verbose confusing code
>>
File: bravo_cia.jpg (86 KB, 1280x715) Image search: [Google]
bravo_cia.jpg
86 KB, 1280x715
>>53898462
What happened to the CIA?
>>
>>53898604
> 4 functions
off with the set idea.

> What if we consider that I'd want each variable (p53, Mdm2, etc) to refer to a function? If I have a small set of functions (about 4) and each variable is supposed to point to that function, would it be possible to get something like the following from a text file (given that the text file contains info on which function maps to which variable)?

>>> def a():
... x = y
... return z
...
>>> a
<function a at 0x7f3c2585f598>
python functions can be manipulated freely, and the association between the name "a" here and the function is no different from an integer variable, so constructing a dict with function as mapped-to values is perfectly possible. Besides, I see no problem in the text-file part. is this
p53 = funcA()
Mdm2 = funcB()
p21 = funcC()
PIP3 = funcB()
format final? I suppose it's not, it's cumbersome
>>
>>53898659
That's perfect. Thank you so much for taking the time, friend.
>>
>>53898695
>is this [...] format final?
Nah, I'm just making it up because my actual code is mostly in my head right now, heh.
>>
>>53898696
actually I just tested this and you'd have to define the functions before the dict, but same principle
>>
>>53898714
good. Have a nice day and good luck with your bioinformatics. Guess I should finish my own physics calculations btw
>>
>>53898667
J A V A
A
V
A
>>
>>53898692
Crashed in the plane

with no survivors.
>>
>>53896902
why doesn't

    buffer->mi.dx = (0 * (0xFFFF / SCREEN_WIDTH));
buffer->mi.dy = (0 * (0xFFFF / SCREEN_HEIGHT));


return set both to zero? aren't they being multiplied by it?
>>
>>53898667
make a RecyclerViewFactory that with an AbstractRecyclerViewAdapter and AbstractRecyclerViewViewHolder and if you used generics properly you'll be able to quickly implement 90% of any app

I'm only half joking, android programming is srsly fucked up
>>
>>53898762
>crashing in a plane
>not "crashing a plane"
"Yeah, we were flying our Cessna inside the plane when we crashed and died."
>>
rate my shitty code
http://pastebin.com/QpGivSyD
>>
>>53898795
I don't understand any three of those things they make no sense to me only thing I understand is generics in Java
>>
>>53898598
fucking disgusting retard it's a matter of style and readability
>>
>>53898814
RecyclerView is an android-provided class that controls big lists of things you scroll through.
>>53898795 is something I did a while ago because they're tedious and repetitive to implement.

If you're actually serious about learning android, and you know what generics are, go figure out what is an "Activity", "View", and "Service" and then get going
>>

package simpletexteditor;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TabPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

/**
*
* @author Alex
*/
public class SimpleTextEditor extends Application {


@Override
public void start(Stage primaryStage) {
Button btn = new Button();
btn.setText("Say 'Hello World'");

Button but = new Button();
but.setText("Moo");

btn.setOnAction(new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});

but.setOnAction(new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent event) {
System.out.println("Moo!");
}
});


StackPane root = new StackPane();
StackPane moo = new StackPane();
root.getChildren().add(btn);
root.getChildren().add(but);

Scene scene = new Scene(root, 300, 250);


primaryStage.setTitle("I Love Java!");
primaryStage.setScene(scene);
primaryStage.show();
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}

}

>>
>>53898809
please please don't name your list "list"
that's like one of the few wrong things you could name it
>>
>>53898809
USE MEANINGFUL VARIABLE NAMES YOU PRANCING LALA HOMO MAN
>>
>>53898884
this, list overrides the built in list() function
ideally name it after what it's used for but at least call it my_list, or array, or something
>>
>>53898809
P Y T U R D
Y
S
H
I
T
>>
>>53898906
ruby is a comfier meme language
>>

int num = 5;

int[] list = new list[1];
list[0] = num;

System.out.println(list);

>>
What are the resources and documentation I need to program device drivers? I've done some playing around with an FPGA and now I'd like to try making it a USB device. I was thinking at first just using its buttons and switches as a USB numpad.
>>
>>53898923
not sure if trolling or just retarded
>>
>>53898743
V E R B O S E

E

R

B

O

S

E
>>
>>53898874
>>53898923
>>53898790
>>53898695
>>53898659
>>53898604
>>53898496
>>53898431
>>53898383
how to post code like this?
>>
>>53898981
>>51971506
>>
>>53898996
thanks bro
>>
File: haskell-fb-industry.png (1 MB, 1128x1080) Image search: [Google]
haskell-fb-industry.png
1 MB, 1128x1080
>>53899062

Join is in /fpg/ - functional programming general

don't be autists
>>
>>53899042
It does, yes.
cout << "Hello, world!" << endl;
I've screwed up a few posts and made the formatting weird because I forgot to close the tag. I guess I'm too used to my IDE auto-completing snippets for me.

Like this desu
>>
#hello
print("Hello")


is it working?
>>
>>53899077
no
>>
>>53899077
So what now, /dpt/ dies?
>>
>>53898809
"list" should fly out the window, I agree with >>53898884
>>53898891
>USE MEANINGFUL VARIABLE NAMES YOU PRANCING LALA HOMO MAN
they probably don't have english as their first language (traingle (sic) typical non-phonetic)

range(1,4)
could be just
range(3)


for x in range(1,4):
list.append(input())

for i in list:
z = int(i)
squares.append(z*z)

there's no reason to have two separate loops there, especially since you're prompting for all 3 numbers, an only after that checking that they are well-formatted (int(i)).
You could make a good use of range-expressions (
[i*i for i in range(1,5)]
give
[1, 4, 9, 16, 25]
) instead of append bullshit. also, outright sort this list of sides if you're going for it. and you probably don't need to do int(y) in the last line, it's a number already.

My version, in my own memelanguage:
côtés = [int(input("entrez un côté: ")) for i in range(3)]

côtés.sort()
[cathète_mineur, cathète_majeur, hypothénuse] = côtés

if cathète_mineur**2 + cathète_majeur**2 == hypothénuse**2:
print("Ce triangle est rectangle")
else:
print("Ceci n'est pas un triangle rectangle")
>>
(defun rec () (rec) (rec))
(rec)

(rec)

(rec)



>>
>>53899077
>don't be autists
you're the autists
>>
how many programming courses have you guys taken? I have taken 4 strictly programming courses at university
>>
>>53899119
you are genius
>>
a, b = b, a if a > b
b, c = c, b if b > c
a, b = b, a if a > b
(ruby example)

Do you guys think inline bubblesort is a good way of sorting just three numbers?
>>
>>53899244
yes but ruby is SHIT
>>
File: hL8Os0xl.jpg (21 KB, 630x640) Image search: [Google]
hL8Os0xl.jpg
21 KB, 630x640
>>53899211
Obviously we're the best! (Let the shitstorm begin €€€)
>>
>>53899272
>>53899119
teach me
>>
>>53899272
>France
>White
>>
>>53899258
ruby is the comfiest meme language though
>>
>>53899434
>using a garbage lang is ok if we call it a meme
>>
>>53899478
>not being a hipster "coding" ruby in atom
ISHYGDDT
>>
>>53899491
What does ISHYGDDT mean?
>>
File: 1450400267716.jpg (30 KB, 475x533) Image search: [Google]
1450400267716.jpg
30 KB, 475x533
>>53899498
>being this new
>>
>>53899498
>>53899503
>2016
>considering yourself an oldfag
>not knowing what ISHYGDDT
>>
>>53899503
Well excuse me for not browsing meme boards like /sci/
>>
>>53899546
kill yourself namefag
>>
How do I average 6 ints?
>>
>>53897075
If you're this new to programming, you shouldn't even be in this thread. Pick up an introductory book and get to work.
>>
File: 1368637306212.jpg (35 KB, 250x250) Image search: [Google]
1368637306212.jpg
35 KB, 250x250
>>53899546
>tripfag
>doesn't know what ishygddt this means
>clearly can't use google
I hope this is b8
>>
>>53897668
regex
>>
>>53899602
Where does it state in /dpt/ that it's only for those that are proficient in programming? I thought /dpt/ was for programmers of all kinds of skill and proficiency

>>53899623
Alright, it is. You got me.
>I sure hope you guys didn't do this
>>
>>53899589
it's impossible to do it with full accuracy in C
>>
>>53899589
avg = lambda *args: sum(args) / len(args)
>>
File: 1457306107407.jpg (125 KB, 800x707) Image search: [Google]
1457306107407.jpg
125 KB, 800x707
>>53899639
>>I sure hope you guys didn't do this
Holy fucking shit, you can't make this shit up.

Real talk, are you fucking retarded?


Also, have to build a calculator in MIPS.

Who /assembly/ here?
>>
File: db0[1].jpg (26 KB, 349x642) Image search: [Google]
db0[1].jpg
26 KB, 349x642
>>53899639
>>
>>53899639
Drop the trip loser
>>
>>53899639
>I thought /dpt/ was for programmers of all kinds of skill and proficiency
you are not programmer. you're a newfag trying to do learn programming
>>I sure hope you guys didn't do this
anon...
>>
File: microexpressions-disgust.jpg (28 KB, 524x336) Image search: [Google]
microexpressions-disgust.jpg
28 KB, 524x336
>>53899639
>I sure hope you guys didn't do this
so close...
>>
>>53899589
Output a random number and hope for the best
>>
>>53899589
find the largest and smallest number. now you have two ints. finding their average is a previously solved problem so we are done.
>>
how do i make a dict that depends on other things in the same dict update when its dependencies change?

like this (assume the gates are defined already)
myGates = {
"first": ANDgate(myGates["second"],myGates["third"]),
"second": NOTgate(1),
"third": NOTgate(0)
}


For
print myGates["first"]
this outputs 0 just fine, but when I input 0 in the second gate (
myGates["second"] = NOTgate(0)
) I want the output of
myGates["first"]
to be 1, but it's 0.

please respond
>>
>>53899589
How do you average N ints?
>>
File: Untitled.png (49 KB, 1401x747) Image search: [Google]
Untitled.png
49 KB, 1401x747
How can I read related and ordered data which is fractured into different sources and display them concurrently as shown on the right-hand side of this picture?

I know I'm probably going to have to use arrays but I'm unsure which will be best suited.

Doing this in C# by the way.
>>
>>53899589
int avarage(int a, int b, int c,
int d, int e, int f) {
int sum;
int rems;

sum = a/6 + b/6 + c/6 + d/6 + e/6 + f/6;
rems = (a%6 + b%6 + c%6 + d%6 + e%6 + f%6) / 6;

return sum + rems;
}
>>
>>53899077
Dumb frogposter
>>
>>53899935
paste file1.txt file2.txt file3.txt file4.txt > merged.txt
>>
>>53899935
Put it into four different columns in an excel file?
>>
>>53899889
>please respond
ok
>>
>>53899889
lazy evaluation maybe. use a dictionary constructor that gets its own result as an argument in an unevaluated form, and then forces parts of itself - a process which may itself force other parts - as needed or immediately. Then, if you represent your alterations as a function that constructs the altered version of the dictionary out of the original version, you can just model it as function composition.

import Data.Map.Lazy as Map
import Data.Function(fix)

myGates self = Map.fromList [("third", 0), ("second", 1), ("first", (Map.!) self "third" + (Map.!) self "second")]
myGates' = Map.insert "second" 0 . myGates

main = do
print $ fix myGates
print $ fix myGates'

(Haskell)
result:
fromList [("first",1),("second",1),("third",0)]
fromList [("first",0),("second",0),("third",0)]



See what I mean?
>>
>>53899937
>avarage(-294967338,-294967352,-294967366,-294967380,-294967394,1999999965)
>87527190
lad...
>>
>>53899937
>avarage
>>
Is there a way to tell if
git pull
actually retrieved anything new without parsing it's text output?
>>
>>53900303
>anything new
you mean the current branch or anything downloaded? If it's the current branch you'll see soon enough, either because there's a conflict or because there's new shit, and if it's anything, look into git-fetch.
>>
>>53900334
sorry, forgot one detail:
       The names of refs that are fetched, together with the object names they
point at, are written to .git/FETCH_HEAD. This information may be used
by scripts or other git commands, such as git-pull(1).
per git-fetch
>>
>>53900161
No, just output it on a console.
>>
>>53900334
Essentially I just want to update the contents of my local repo from the master, and run a command if there are changes without using hooks. So I need some way of updating the repo and checking if there's actually been changes.

I can just grep the output of `git pull` for "Already up-to-date.", but it would be much more convenient to just be able to eg. check the return value of the command.
>>
>>53899639
Filtered
>>
>>53899589
double avg(const std:vector<int> x) {
double res;
for(const auto e : x) {
res += static_cast<double>(e) / std::vector.size();
}

return res;
}
>>
>>53899639
/^!93GCE9hnmM$/;stub:no;
>>
>>53898119
Wait really? Those are so convenient tho
>>
>>53900505
>>53900463
Why is everyone being triggered by a newbie? I have to start somewhere
>>
>>53900479
what are you doing nigger
>>
>>53900528
It's the tripcode, faggot.
>>
>>53900479
double avg(const std::vector<int> &x)
{
return std::accumulate<double>(
x.begin(),
x.end(),
0
) / x.size();
}
>>
>>53900548
Tripcode aside, everyone's still salty about my lack of knowledge. I mean what's up with that? I thought /dpt/ was a place to learn and ask questions
>>
>>53900565
No, /SQT/ is a place to learn

/dpt/ is where you defend your programming language
>>
>>53900565
This thread is pretty hostile to noobies but it's mostly the trip because it singles you out as a massive fag
>>
>>53900565
You thought wrong.
>>
Learning Python by using SimpleITK to process DICOM files.
>>
>>53900565
I think the old adage 'LURK MORE FGT' applies here
>>
>>53900627
This, if you're a noob don't draw attention to yourself
>>
>>53900588
This. We only """tolerate""" Ruby and OSTGP because they actually know what they're doing.
>>
>>53900711
Haha, no.
>>
THREAD SAFETY ISNT REAL
>NOTHING IS REAL
D I S A R R A Y
I
S
A
R
R
A
Y
Thread replies: 255
Thread images: 31

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.