• An old favorite feature returns: Q&ERA is back! This time we'll be collecting questions for Remedy Entertainment, makers of Max Payne, Alan Wake, Quantum Break, and Control. Members can submit questions for the next 11 hours, 36 minutes, 7 seconds. Submissions will close on Dec 12, 2019 at 12:00 AM.

Programming |OT| Functional, Imperative, OOP, Cargo-Cult,... all are welcome!

Oct 27, 2017
7,406
The Last Wizard
At a glance,
Code:
randNum = (int)(Math.random()*10);
should not be in the while loop. You keep setting it to a new number instead of leaving it be.

Set the number before your while loop and then just have the user keep guessing. You shouldn't have to set randNum more than once
I just noticed it. I copy and pasted it out of the loop but never deleted it in the loop. That's what happens when you haven't had enough rest in the last few days from studying for midterms, writing a paper and doing programming HW:P Thanks, man.
 

vypek

Member
Oct 25, 2017
4,860
I just noticed it. I copy and pasted it out of the loop but never deleted it in the loop. That's what happens when you haven't had enough rest in the last few days from studying for midterms, writing a paper and doing programming HW:P Thanks, man.
Haha, no problem. I've had similar issues in the past where I forget to comment out stuff in testing and the issue persists.
 

Sesuadra

Member
Oct 26, 2017
1,798
I've a big test on Thursday about entity relationship model/diagram, normalisation 1NF-3NF and some sql..I might just need you all on Wednesday when I study. ;_;"
 

Ledbetter

Member
Oct 27, 2017
24
I suppose there is another discussion just for web development related stuff, couldn't find it, but I'm not that interested in this discussion leaning heavily into web-dev, heh.
I've a big test on Thursday about entity relationship model/diagram, normalisation 1NF-3NF and some sql..I might just need you all on Wednesday when I study. ;_;"
Why wait until the day before to study... when you can skim through the concepts 1 hour before the test?
 

Gridman

Member
Oct 25, 2017
96
I'm happy to see a thread like this. Once I couldn't afford to finish my CS degree, I gave up on doing anything related to programming. I hope it's not too late to start over with the basics and build a solid foundation.
 

compo

Member
Oct 27, 2017
2,773
Can someone tell me why this no longer works for me? I used to have a bookmarklet that when I clicked it would open all unread threads in new tabs. This worked prior to iOS 11 and Safari 11 on my Mac. I tested it in Chrome and it also fails there. The problem is when I run it now, it just opens the first link and then stops. Did something happen to how javascript is handled so window.open no longer works in for loops?

Basically, what I want to do is click that in a bookmarklet and have all unread threads open. Everything seems to work, the array is the correct length, but that for loop where it opens the URLs just opens the first one and then stops.

Code:
javascript:
var SITE = location.host;
if(SITE=="www.resetera.com"){
    var arr = [], l = document.links;
    for(var i=0; i<l.length; i++) {
        if(l[i].href.indexOf("/unread") !== -1)
            arr.push(l[i].href);
    }
 
 
    for ( var i = 0; i < arr.length; i++) {
        window.open(arr[i]);
     }
 
}
I tried testing your code on my machine, and the window.open() calls were being blocked for me too. But I found out that popups were being blocked for restera.com in my browser, and when I turned that off, your code worked. I'm on Chrome, by the way.

Source on solution: https://stackoverflow.com/questions/11821009/javascript-window-open-not-working
 

metaprogram

Member
Oct 28, 2017
973
Where is cppking? I want to ask him what he thinks of the modules dumpster fire.
So which part of modules do you think is a dumpster fire? I'm guessing you mean the fact that there are two competing proposals? Because I definitely have some thoughts on that, being relatively "close" to the whole situation.
 

kristoffer

Banned
Oct 23, 2017
2,048
What ever do you mean? I'm just c++, no more no less :)

Edit: to be honest in hindsight I kind of wish I had chosen something even more different. I had the idea for the name "metaprogram", but at that point I had already registered with this.
If you'd like a name change, PM me.
 

Ledbetter

Member
Oct 27, 2017
24
I'm happy to see a thread like this. Once I couldn't afford to finish my CS degree, I gave up on doing anything related to programming. I hope it's not too late to start over with the basics and build a solid foundation.
It's never too late! Programming has to be undisputedly the most resourceful topic you can find on the Internet, although of course that means a lot of the resources you find may not be the best. I'll try to gather information that I found useful over my college years and try to request them to be added to the OP.
 

rucury

Avenger
Oct 25, 2017
569
Puerto Rico
Hello, friends! I like programming too. But only in Python. Any other language must justify its own existence by being used to correctly determine whether or not an arbitrary Python program of arbitrary length eventually terminates. Else, it must cease to be used.

I’m just kidding, I also like C++. BUT NO METAPROGRAMMING OR ELSE
 

gryvan

Member
Oct 25, 2017
357
Hi I've lurked in this OT more or less from GAF before
so I'm only just starting to post here to get a bit more acquainted with everyone.

I personally love C++ myself but I have this weird mental block everytime I wanna start a small project where it feels like everything is overwhelming and I just stare at my visual studios and go..... Any way to over come this obstacle? or is it just keep practicing slowly on small things.

I also wanna kinda break into programming more to see more job opportunities myself. (My work does not relate to anything programming related lol)
 
Oct 25, 2017
2,670
Hi I've lurked in this OT more or less from GAF before
so I'm only just starting to post here to get a bit more acquainted with everyone.

I personally love C++ myself but I have this weird mental block everytime I wanna start a small project where it feels like everything is overwhelming and I just stare at my visual studios and go..... Any way to over come this obstacle? or is it just keep practicing slowly on small things.

I also wanna kinda break into programming more to see more job opportunities myself. (My work does not relate to anything programming related lol)
Understand the big picture but don't focus on it. Split things up until it's small enough you can get a handle of. Keep doing this. Once you have most of the individual components, start building the system to integrate them.
 

LL_Decitrig

User-Requested Ban
Banned
Oct 27, 2017
10,334
Sunderland
Forth

Nearly a year ago now, I thought about relatively high level languages that could run on really minimal systems (such as those little eight-legged Atmel AVR chips, including ATtiny85.) While it's possible to adapt Arduino and the like, I was drawn to Forth as a way to use the functional paradigm I favour while keeping the code very tight. It's about the smallest high level language you can use on a really tiny processor with a Harvard architecture.
 

kristoffer

Banned
Oct 23, 2017
2,048
Forth

Nearly a year ago now, I thought about relatively high level languages that could run on really minimal systems (such as those little eight-legged Atmel AVR chips, including ATtiny85.) While it's possible to adapt Arduino and the like, I was drawn to Forth as a way to use the functional paradigm I favour while keeping the code very tight. It's about the smallest high level language you can use on a really tiny processor with a Harvard architecture.
Stack based languages are incomprehensible to me. I tried Factor, and while it was a mind-expanding experience, I couldn't imagine living in such a world. For a domain like embedded programming, though, that sounds pretty nifty.
 

LL_Decitrig

User-Requested Ban
Banned
Oct 27, 2017
10,334
Sunderland
Stack based languages are incomprehensible to me. I tried Factor, and while it was a mind-expanding experience, I couldn't imagine living in such a world. For a domain like embedded programming, though, that sounds pretty nifty.
Yes, the stack-based threaded languages like Forth are from another era, when they provided a sweet spot by giving you an interactive environment for creating tight, efficient code in handy bite-sized portions. They're only useful in certain niches, in the hands of highly competent engineers who can devote a lot of time to learning the paradigm.
 

thesoapster

Member
Oct 25, 2017
2,714
MD, USA
C# .NET slut here. I'm doing full stack-ish work (web server admin, DB design, framework programming, services programming, and front end web dev).
 

metaprogram

Member
Oct 28, 2017
973
there's definitely some truth in there, but you have to understand that the author of that blog post (whom I know by the way, so I say this with <3) is a bit of a... "character". I mean watch her cppcon talk There Will Be Build Systems: I Configure Your Milkshake to get an idea. Just the first 15 seconds is enough before you're like "wtf is going on here?" Or even just read the title.

What's true is that Microsoft has decided how Modules should be and they're not open for discussion. This is pretty fucked up, honestly, because it goes against the entire spirit of a committee. Once you bring Clang's modules proposal into the picture it starts bordering on... sinister for lack of a better word. One person (who, whaddaya know happens to also be the implementer and designer of Modules on the Microsoft side) is reponsible for editing and controlling the content of the Modules TS. It doesn't take a rocket scientist to figure out that this is a serious conflict of interest when you've got proposals A and B, and the author of A is the gatekeeper to what goes in to the final draft.

The only people that are currently happy with the Modules TS as proposed by Microsoft are the people who don't mind literally re-writing all of their header files from scratch. As you can imagine, that's a ridiculous proposition for people working on existing codebases. or using 3rd party libraries that they can't change. At CppCon a few weeks ago John Lakos (whom you might recognize as the author of the classic book Large Scale C++ Software Design) got up and asked a question about this, and man was it uncomfortable. You can see a video of the exchange here (Coincidentally, if you rewind from the time I linked, the previous question is from Isabella, the author of that blog post). It starts out tame but by the end he's completely steamrolling the speaker over these types of issues.

In an ideal world, Microsoft's modules is honestly pretty good. If C++ had no baggage, and you could approach this from a purist language design standpoint, it's probably the right design. It seems like somethign that even, 10-20 years from now, might be good, as we could get there incrementally. But it completely ignores the practical reality that it's totally unsuitable for retrofitting existing code, and they seem either unwilling to acknowledge that that's a problem, or at the very least unsympathetic with the millions of people who literally will not be able to use modules as a result.

All is not lost though. There's a lot of efforts going on behind the scenes to bridge the gap between the two proposals, and although the level of unwillingness to engage and compromise with the rest of the C++ community on the matter is honestly a little bit unprecedented, at the end of all this there's still going to be a vote, and if the vote doesn't pass (which, in it's current form, it won't), they will look back on this and wish they had been less dismissive of the community's concerns.

Hopefully it doesn't need to come to that, and we can get something good before it ever reaches a vote in the first place. That's still possible, they're just making it much harder than it really should be.
 
Oct 27, 2017
1,068
Ireland
[strike]Hey! Hope everybody here's made the jump successfully. I've a quick question which I'm hoping somebody could help me with. I'm currently working on a project where I'm using Matlab, but I'm not totally familiar with it and have a pretty small (I presume basic) question I'm hoping somebody here might be able to answer quite easily that I cannot seem to find online (most likely using wrong terms).

I'm looking to use the Matlab fzero function to find a root of a function, but I want to track how many iterations it takes to find that root, and save it as a variable I've named "TotalIterations" and want to keep track of the validity of convergence using "ConvergenceType".

From this link: https://uk.mathworks.com/help/matlab/ref/fzero.html#btoc6lj-16 I can see that all of this information is stored/captured from the function fzero, and what I basically want to do is let "TotalIterations = iterations" and "ConvergenceType = flag", but I'm not entirely sure how to extract that information from fzero as I'm not entirely sure where that information is actually kept or how to call it.

I know it's probably not something very tricky, but the Matlab page isn't really shedding light on how exactly to do this, so any help would be really appreciated.[/strike]

EDIT:
Well, what do you know, just after posting I got it. For anybody else who may be wondering how to do this in the future, my workaround was (inefficient, but quick and easy):

-whatever code you have-

if exitflag==x,
TotalIterations=iterations.iterations %This is how you call this in the structure table.
ConvergenceType=x

And then just continue with the few different cases for exitflag which are possible. Not a very clever workaround, but very easy to use.
 
Last edited:

Blazo

Member
Oct 27, 2017
23
I'm just joking about drinking alcohol. My software architect, who I learn the most from, doesn't drink anymore. Interaction is key. It's really about spending the time going through your work and discussing it.
Haha, i actually found happy hour podcast after your response, that is how my sober mind works after night before.

I'm going through university at the moment so pair-programming and everything else is must.
 
Oct 25, 2017
6,037
I tried testing your code on my machine, and the window.open() calls were being blocked for me too. But I found out that popups were being blocked for restera.com in my browser, and when I turned that off, your code worked. I'm on Chrome, by the way.

Source on solution: https://stackoverflow.com/questions/11821009/javascript-window-open-not-working
Thank you so much for checking!

What's odd for me (again, on Safari) is that even when I disable the pop-up blocker built in to both the Mac and iOS version of the browser, it still doesn't seem to work. Only the first instance opens a new tab. I wonder if Apple did something to Safari in iOS 11 and High Sierra to just never let it happen even if the pop-up blocker is disabled. I've tried searching for this issue specific to the new Safari versions but can't find anything. And I really don't know another way to accomplish this, sadly.
 

thesoapster

Member
Oct 25, 2017
2,714
MD, USA
Haha, i actually found happy hour podcast after your response, that is how my sober mind works after night before.

I'm going through university at the moment so pair-programming and everything else is must.
If you have any say in group projects, be careful about who you have as a team. I mostly got assigned to useless people who I had to effectively carry.
 

firehawk12

Member
Oct 25, 2017
6,839
Hi, I just had a python question. If I wanted to print a tab deliminated list where I don't know the length of the strings in the list but I still want them to line up, what would I do?

I know if I use '\t', it doesn't work because it doesn't account for the length of the string and just puts a tab at the end of it, so I'm not sure what I should do.
For example, this wouldn't work:
print("Hello"+'\t'+'World')
print("Hellooooooo"+'\t'+'World')
(I would want the "World" of both lines to line up with each other).

Is this something where I should import a table library, or is there something I can do with string manipulation to get what I want?

Thanks.
 

Eridani

Member
Oct 25, 2017
699
Hi, I just had a python question. If I wanted to print a tab deliminated list where I don't know the length of the strings in the list but I still want them to line up, what would I do?

I know if I use '\t', it doesn't work because it doesn't account for the length of the string and just puts a tab at the end of it, so I'm not sure what I should do.
For example, this wouldn't work:
print("Hello"+'\t'+'World')
print("Hellooooooo"+'\t'+'World')
(I would want the "World" of both lines to line up with each other).

Is this something where I should import a table library, or is there something I can do with string manipulation to get what I want?

Thanks.
You can use string formatting to pad words with spaces to a desired length. For example:
Code:
>>> '{:10}'.format('12345')
'12345     '
This will pad the string in format() to a length of 10 characters. If you know the longest word in your list, then you can simply substitute 10 with that and get the desired result. If you can't do that for some reason (and if you have the strings in a list, I don't see why you couldn't), then you can pick a suitably large number and hope none of the strings are larger than that.
 

firehawk12

Member
Oct 25, 2017
6,839
You can use string formatting to pad words with spaces to a desired length. For example:
Code:
>>> '{:10}'.format('12345')
'12345     '
This will pad the string in format() to a length of 10 characters. If you know the longest word in your list, then you can simply substitute 10 with that and get the desired result. If you can't do that for some reason (and if you have the strings in a list, I don't see why you couldn't), then you can pick a suitably large number and hope none of the strings are larger than that.
So the strings are user inputted, which means the length is unknown.
But I guess I could loop through the list of strings, find the longest length, and then use that as the basis? Is there a way to make that formatting take a variable?

For example: '{:10 + length_of_longest_string}'.format('12345')

Or does it have to be a constant?
 

Eridani

Member
Oct 25, 2017
699
So the strings are user inputted, which means the length is unknown.
But I guess I could loop through the list of strings, find the longest length, and then use that as the basis? Is there a way to make that formatting take a variable?

For example: '{:10 + length_of_longest_string}'.format('12345')

Or does it have to be a constant?
It can be a variable too, although the syntax is slightly different:
Code:
>>> n = 10
>>> '{:{width}}'.format('12345', width=n)
'12345     '
Or you can just use something like ljust if you don't want to bother with the whole formatting thing:
Code:
>>'12345'.ljust(n)
'12345     '
As for finding the longest word, as long as all the strings are saved to a list before they are printed, you can find the maximum length pretty easily. Either loop through the list, or use list comprehension:
Code:
>>> a = 'aa'
>>> b = 'bbb'
>>> c ='cccc'
>>> d = 'd'
>>> strings = [a, b, c, d]
>>> lens = [len(x) for x in strings]
>>> print(lens)
[2, 3, 4, 1]
>>> print(max(lens))
4
List comprehension might look a bit advanced, but it's by far one of the best features in python so it's well worth learning.
 

metaprogram

Member
Oct 28, 2017
973
So the strings are user inputted, which means the length is unknown.
But I guess I could loop through the list of strings, find the longest length, and then use that as the basis? Is there a way to make that formatting take a variable?

For example: '{:10 + length_of_longest_string}'.format('12345')

Or does it have to be a constant?
Something like this probably works. Haven't tested it but it seems like what you want.

Code:
# split each line into a list of words (e.g. columns), and over the course of doing
# this for every line, figure out the width of the longest word in each column.
# Return a new list where the each line is split into words, as well as a list
# representing the width needed for each column
def split_analyze(lines):
    new_lines = []
    column_lengths = []
    for l in lines:
        words = l.split()
        new_lines.append(words)
        lengths = [len(word) for word in words]

        lc = len(column_lengths)
        lw = len(words)
        max_words = max(lc, lw)
        column_lengths.extend([0] * (max_words - lc))
        lengths.extend([0] * (max_words - lw))
        for (i, (j, k)) in enumerate(zip(lengths, column_lengths)):
            column_lengths[i] = max(j, k)
    return (column_lengths, new_lines)

# Print all lines with the correct padding at each column
def tabularize(columns, lines):
    for line in lines:
        for (width, word) in zip(columns, line):
            print("{0:<{width}}".format(word, width=width), end=' | ')
        print()
 
OP
OP
Moosichu

Moosichu

Member
Oct 25, 2017
699
Hi everyone, had a busy week and weekend. Gonna look at all the OP suggestions tomorrow and integrate the changes.

Also, learned some Rust today and it is really cool.
 

culexknight

Member
Oct 25, 2017
16
Hey all,

C#/.NET/*-schema/data-warehouse professional of 5 years. Done applications, web backends, web front ends, data warehousing... And tons of other things on a non-professional scale (C++/the mandatory gamedev/operating system design/etc). ~10 years of exp at this point. Open to help/mentoring/being helped & mentored.

Do we have a Discord?
 

metaprogram

Member
Oct 28, 2017
973
There is a discord, Specific Power Ranger mentioned on the previous page. but you have to PM him to get a link. Seems like it would be better to just put a GIF of the link, perhaps even in the form of a QR Code. Would do just as good as "quote to reveal" to prevent abuse.
 

Halcy Caritas

Member
Oct 26, 2017
135
I'm going to be going on an adventure trying to learn different languages as someone whose only experience coding was basic beginner's high school Java. Definitely following this thread.
 

dabig2

Member
Oct 29, 2017
2,770
What's up programming-era. Dabbled in a bit of everything, but right now I"m settled in .NET/C# doing full stack nonsense. Never thought I'd touch the web before as I loved my comfy back-end, but here I am messing around with enterprise web applications.

C# .NET slut here. I'm doing full stack-ish work (web server admin, DB design, framework programming, services programming, and front end web dev).
Ditto. And fully agreed about the happy hour. I think doing .NET full stack made me more of an alcoholic than I already was. Nothing better than doing a bit of server debugging at home with a bit of drank in you. It makes the pain go away.
 

firehawk12

Member
Oct 25, 2017
6,839
Something like this probably works. Haven't tested it but it seems like what you want.

# Print all lines with the correct padding at each column
def tabularize(columns, lines):
for line in lines:
for (width, word) in zip(columns, line):
print("{0:<{width}}".format(word, width=width), end=' | ')
print()
[/code]
I've never seen zip before. That lets you create tuples from two lists? That's pretty crazy. lol

If I wanted to space out the longest string with a predefined spacing, like a tab, is there a constant that's the equivalent of '\t' that I can add, or would I just hard code '4' in the format(word, width=) part?
 

metaprogram

Member
Oct 28, 2017
973
Code:
tab = “ “ * 4
Don’t ever use ‘\t’. It’s not portable and will give you different results on different machines

The code i posted should already align each column. If you want to add additional spacing, just change “width=width” to something like “width=width+4”
 
Last edited:

Galaxea

Member
Oct 25, 2017
361
Orlando, FL
Is python a good language to begin learning to see if I like coding? I am nearly 35 working as a supervisor in retail while picking up photography gigs off and on, but I'm not certain of my future in either of them. It would at least be a good hobby since I've enjoyed the little bit I've dabbled into before.
 

metaprogram

Member
Oct 28, 2017
973
I’d recommend c# if you want to see if you like coding. Mostly because it has excellent tool support making it very easy to get into without worrying about a bunch of stupid crap.

Python is ok too, but I would pick C# first imho
 

MikeRahl

Member
Oct 27, 2017
276
How does everyone deal with burn-out?

Feeling pretty grim at work lately. I'm in a good position in a good job but some of the projects we are working on are just dragging on and on. I have a pretty good work-life balance (pretty much entirely 8-5) so I can't complain too much but the days drag on and on. I've thought about perhaps spreading my wings a bit, but all my experience is in this company, and the team has literally not grown or shrank in the 7 years I've been here so I worry about references. I wouldn't mind getting into Android development to build out a portfolio a bit but coming home from work I just want to veg out with my family. The progrmamming scene in my city (medium size in Canada) seems pretty closed in so not much networking going on there, I am heading to a conference soon so maybe I can meet some like-minded people there.

On the plus side, if anyone wants to feel better about how their company secures sensitive information, send me a message... I've seen some stuff this last couple months that would make your toes curl.
 

Galaxea

Member
Oct 25, 2017
361
Orlando, FL
I’d recommend c# if you want to see if you like coding. Mostly because it has excellent tool support making it very easy to get into without worrying about a bunch of stupid crap.

Python is ok too, but I would pick C# first imho
Nice! I just read up on it. It sounds like a fun place to start. I need to find a good beginners course on it.

Edit: I am going to dig through Bob Tabor's course on it.
 
Last edited:

vypek

Member
Oct 25, 2017
4,860
Is anyone here using Firefox developer edition? I'm trying to compare Quantum and Developer editions and the only different I can really see at the moment is the difference in logo, theme and the icon that developer has for developer tools automatically enabled. Is there anything else in there that anyone has noticed? The rest seems the same to me.
 

Lonely1

Member
Oct 26, 2017
3,291
Hey guys. I'm wondering, which is the best online resource to learn Python in an structured environment? I already have a fair share of coding experience.
 

peyrin

Member
Oct 27, 2017
3,988
California
Honestly if you have a decent amount of coding experience, Python is really intuitive to learn on your own. I pretty much picked it up as I was coding a personal project - just be prepared to have dozens of Stack Overflow tabs open at all times. Of course you could just use some of the other links posted in here.

Studying for a CS degree btw. If only some startup could give me an internship.