• Welcome to the new Internet Infidels Discussion Board, formerly Talk Freethought.

The Programming Thread

Jimmy Higgins

Contributor
Joined
Feb 1, 2001
Messages
38,375
Basic Beliefs
Calvinistic Atheist
First there was spaghetti code, then there was structured programming, then came object oriented programming to eal with large scale multi programmer systems.Any C++ OOP people? Is there a coding school of thoutht you use or do you just have itt it?

Productivity remorse? That is a new one. I always took away a good feeling being productive. I learned early on that productivity paid higher, but more important was the more productive and independent you were the more freedom you had.
Productivity means fewer people get paid. I'm working on the mother of all VBA assisted spreadsheets to make the work of 10 people full time, possible for 2.
 

rousseau

Contributor
Joined
Jun 23, 2010
Messages
12,489
Wading back into Java for the first time in about.. 2 years?

ihnmotp.jpg


Thinking.. what the hell is all of this crap!?
 

steve_bank

Diabetic retinopathy and poor eyesight. Typos ...
Joined
Nov 10, 2017
Messages
11,083
Location
seattle
Basic Beliefs
secular-skeptic
First there was spaghetti code, then there was structured programming, then came object oriented programming to eal with large scale multi programmer systems.Any C++ OOP people? Is there a coding school of thoutht you use or do you just have itt it?

Productivity remorse? That is a new one. I always took away a good feeling being productive. I learned early on that productivity paid higher, but more important was the more productive and independent you were the more freedom you had.
Productivity means fewer people get paid. I'm working on the mother of all VBA assisted spreadsheets to make the work of 10 people full time, possible for 2.



The MS Office suite itself eliminated what were good paying semi skilled jobs and skilled jobs.

In the 90s I inhered a spreadsheet that grew over time uncontrolled and unstructured. A mess that should have been done in in Pascal or Basic even.
 

rousseau

Contributor
Joined
Jun 23, 2010
Messages
12,489
Wrote one of the most complicated algorithms in my career yesterday (all the while feeling like garbage which made it more of a miracle). I was going to try to reproduce the code here but it would probably make no sense out of context. But the problem went something like this:

Code:
1 Query all blood sample records for every patient encounter in the hospital
2 Only pull records from each patient's most recent encounter
3 If that encounter's set of records includes a record of type 1, with field A populated
	- Print the most recent record of that type
	- Don't print the other records in the set
4 If that set of records includes a record of type 1, without field A populated
	- and that set of records has no records of type 1 with field A populated
	- and that set of records contains a record of type 2
	- Print the record of type 1 and 2

Took me a little longer than usual to wrap my head around it. The tricky part is that it needed nested loops, and on point 4 it needed two nested loops within a loop, which was also contingent on point 3 already being dealt with.

Originally I attempted to flag every single record with an is_this_printed_flag, but later switched to flagging types of encounter. First I identified encounters from point 3 as type 1, and then encounters from point 4 as type 2 (any others defaulted to 0). Then when I went to print, as the records were displayed in the correct order and sorted by person, I looked for specific encounter/record types and broke the loop when the correct rows were found.

Still not 100% sure I've got it right, but that is a problem with specification, which is a bit confusing too.

It may not look extremely hard, but most of the time I'm querying and manipulating data, or issuing Google searches. Usually I don't actually have to think this much.
 

Jimmy Higgins

Contributor
Joined
Feb 1, 2001
Messages
38,375
Basic Beliefs
Calvinistic Atheist
Twice today some asshole has blamed me, or my product, for their own fuck up.
My favorite thing is getting a call, "There is something wrong with the log".

No, there likely isn't something wrong, because we would have noticed it 10 years ago!
 

Loren Pechtel

Super Moderator
Staff member
Joined
Sep 16, 2000
Messages
37,501
Location
Nevada
Gender
Yes
Basic Beliefs
Atheist
Wrote one of the most complicated algorithms in my career yesterday (all the while feeling like garbage which made it more of a miracle). I was going to try to reproduce the code here but it would probably make no sense out of context. But the problem went something like this:

Code:
1 Query all blood sample records for every patient encounter in the hospital
2 Only pull records from each patient's most recent encounter
3 If that encounter's set of records includes a record of type 1, with field A populated
	- Print the most recent record of that type
	- Don't print the other records in the set
4 If that set of records includes a record of type 1, without field A populated
	- and that set of records has no records of type 1 with field A populated
	- and that set of records contains a record of type 2
	- Print the record of type 1 and 2

Took me a little longer than usual to wrap my head around it. The tricky part is that it needed nested loops, and on point 4 it needed two nested loops within a loop, which was also contingent on point 3 already being dealt with.

Originally I attempted to flag every single record with an is_this_printed_flag, but later switched to flagging types of encounter. First I identified encounters from point 3 as type 1, and then encounters from point 4 as type 2 (any others defaulted to 0). Then when I went to print, as the records were displayed in the correct order and sorted by person, I looked for specific encounter/record types and broke the loop when the correct rows were found.

Still not 100% sure I've got it right, but that is a problem with specification, which is a bit confusing too.

It may not look extremely hard, but most of the time I'm querying and manipulating data, or issuing Google searches. Usually I don't actually have to think this much.

Sounds like a pain if you have to do it in SQL. No big deal if you can pull in all records identified in #2.
 

rousseau

Contributor
Joined
Jun 23, 2010
Messages
12,489
Wrote one of the most complicated algorithms in my career yesterday (all the while feeling like garbage which made it more of a miracle). I was going to try to reproduce the code here but it would probably make no sense out of context. But the problem went something like this:

Code:
1 Query all blood sample records for every patient encounter in the hospital
2 Only pull records from each patient's most recent encounter
3 If that encounter's set of records includes a record of type 1, with field A populated
	- Print the most recent record of that type
	- Don't print the other records in the set
4 If that set of records includes a record of type 1, without field A populated
	- and that set of records has no records of type 1 with field A populated
	- and that set of records contains a record of type 2
	- Print the record of type 1 and 2

Took me a little longer than usual to wrap my head around it. The tricky part is that it needed nested loops, and on point 4 it needed two nested loops within a loop, which was also contingent on point 3 already being dealt with.

Originally I attempted to flag every single record with an is_this_printed_flag, but later switched to flagging types of encounter. First I identified encounters from point 3 as type 1, and then encounters from point 4 as type 2 (any others defaulted to 0). Then when I went to print, as the records were displayed in the correct order and sorted by person, I looked for specific encounter/record types and broke the loop when the correct rows were found.

Still not 100% sure I've got it right, but that is a problem with specification, which is a bit confusing too.

It may not look extremely hard, but most of the time I'm querying and manipulating data, or issuing Google searches. Usually I don't actually have to think this much.

Sounds like a pain if you have to do it in SQL. No big deal if you can pull in all records identified in #2.

Yea, after a few stumbles I got it in decent time, but I must be out of practice because I hadn't written anything like that in a while.

The overwhelming majority of algorithms I've written in ~ 5 years? Were all simpler than this one. Most of the code I've written that I would call hard were just features I'd never written before and had to seek out a design.
 

AirPoh

Veteran Member
Joined
Nov 13, 2018
Messages
1,129
Location
Connecticut
Basic Beliefs
Atheist
Wrote one of the most complicated algorithms in my career yesterday (all the while feeling like garbage which made it more of a miracle). I was going to try to reproduce the code here but it would probably make no sense out of context. But the problem went something like this:

Code:
1 Query all blood sample records for every patient encounter in the hospital
2 Only pull records from each patient's most recent encounter
3 If that encounter's set of records includes a record of type 1, with field A populated
	- Print the most recent record of that type
	- Don't print the other records in the set
4 If that set of records includes a record of type 1, without field A populated
	- and that set of records has no records of type 1 with field A populated
	- and that set of records contains a record of type 2
	- Print the record of type 1 and 2

Took me a little longer than usual to wrap my head around it. The tricky part is that it needed nested loops, and on point 4 it needed two nested loops within a loop, which was also contingent on point 3 already being dealt with.

Originally I attempted to flag every single record with an is_this_printed_flag, but later switched to flagging types of encounter. First I identified encounters from point 3 as type 1, and then encounters from point 4 as type 2 (any others defaulted to 0). Then when I went to print, as the records were displayed in the correct order and sorted by person, I looked for specific encounter/record types and broke the loop when the correct rows were found.

Still not 100% sure I've got it right, but that is a problem with specification, which is a bit confusing too.

It may not look extremely hard, but most of the time I'm querying and manipulating data, or issuing Google searches. Usually I don't actually have to think this much.

Steps 1 and 2 are something I deal with all the time and I've yet to find an efficient way to do it in SQL. So I first query for the "most recent date (as your example is doing)". I can then query again using the extra criteria, most recent date, from the previous query to get the single record per "patient".
 

rousseau

Contributor
Joined
Jun 23, 2010
Messages
12,489
Wrote one of the most complicated algorithms in my career yesterday (all the while feeling like garbage which made it more of a miracle). I was going to try to reproduce the code here but it would probably make no sense out of context. But the problem went something like this:

Code:
1 Query all blood sample records for every patient encounter in the hospital
2 Only pull records from each patient's most recent encounter
3 If that encounter's set of records includes a record of type 1, with field A populated
	- Print the most recent record of that type
	- Don't print the other records in the set
4 If that set of records includes a record of type 1, without field A populated
	- and that set of records has no records of type 1 with field A populated
	- and that set of records contains a record of type 2
	- Print the record of type 1 and 2

Took me a little longer than usual to wrap my head around it. The tricky part is that it needed nested loops, and on point 4 it needed two nested loops within a loop, which was also contingent on point 3 already being dealt with.

Originally I attempted to flag every single record with an is_this_printed_flag, but later switched to flagging types of encounter. First I identified encounters from point 3 as type 1, and then encounters from point 4 as type 2 (any others defaulted to 0). Then when I went to print, as the records were displayed in the correct order and sorted by person, I looked for specific encounter/record types and broke the loop when the correct rows were found.

Still not 100% sure I've got it right, but that is a problem with specification, which is a bit confusing too.

It may not look extremely hard, but most of the time I'm querying and manipulating data, or issuing Google searches. Usually I don't actually have to think this much.

Steps 1 and 2 are something I deal with all the time and I've yet to find an efficient way to do it in SQL. So I first query for the "most recent date (as your example is doing)". I can then query again using the extra criteria, most recent date, from the previous query to get the single record per "patient".

I was doing it in Cerner CCL, which is a kind of less robust SQL used for reporting (not even sure of the technical term for this type of language). My algorithm for steps 1 and 2 went something like this:

Code:
SELECT
    RECORDS IN ALL ENCOUNTERS
ORDER BY ENCOUNTER etc
HEAD PERSON_ID (group by person id)
    FIRST_ENC_ID = 0.0
DETAIL (all records for person)
    IF(FIRST_ENC_ID = 0.0)
        FIRST_ENC_ID = ENCOUNTER.ENCNTR_ID
    ENDIF

    IF(ENCOUNTER.ENCNTR_ID = FIRST_ENC_ID)
        STORE RECORD
    ENDIF

God I don't even flinch when I write my if statements like that anymore.

The problem with the last two points is that I had to know what was going on in all the records for a given encounter before I could isolate the record I wanted. No way to do that with a query so I had to parse the data.
 

rousseau

Contributor
Joined
Jun 23, 2010
Messages
12,489
And in today's fun I'm updating a label printout. The fun part is that Cerner hasn't developed a way to debug this virtually so I have to issue a print every time I make an update, which involves walking about 50 meters to the printer. I also have to cycle some servers with each update, which takes about 45 minutes to process each time.

I imagine this is similar to what programmers in the 70s and 80s felt like.
 

Loren Pechtel

Super Moderator
Staff member
Joined
Sep 16, 2000
Messages
37,501
Location
Nevada
Gender
Yes
Basic Beliefs
Atheist
And in today's fun I'm updating a label printout. The fun part is that Cerner hasn't developed a way to debug this virtually so I have to issue a print every time I make an update, which involves walking about 50 meters to the printer. I also have to cycle some servers with each update, which takes about 45 minutes to process each time.

I imagine this is similar to what programmers in the 70s and 80s felt like.

90+% of my "printouts" go to a .PDF or .XPS document printer.
 

rousseau

Contributor
Joined
Jun 23, 2010
Messages
12,489
And in today's fun I'm updating a label printout. The fun part is that Cerner hasn't developed a way to debug this virtually so I have to issue a print every time I make an update, which involves walking about 50 meters to the printer. I also have to cycle some servers with each update, which takes about 45 minutes to process each time.

I imagine this is similar to what programmers in the 70s and 80s felt like.

90+% of my "printouts" go to a .PDF or .XPS document printer.

Unfortunately I can only issue the print from a Cerner app to a label printer. Normal rules do not apply.
 

Loren Pechtel

Super Moderator
Staff member
Joined
Sep 16, 2000
Messages
37,501
Location
Nevada
Gender
Yes
Basic Beliefs
Atheist
And in today's fun I'm updating a label printout. The fun part is that Cerner hasn't developed a way to debug this virtually so I have to issue a print every time I make an update, which involves walking about 50 meters to the printer. I also have to cycle some servers with each update, which takes about 45 minutes to process each time.

I imagine this is similar to what programmers in the 70s and 80s felt like.

90+% of my "printouts" go to a .PDF or .XPS document printer.

Unfortunately I can only issue the print from a Cerner app to a label printer. Normal rules do not apply.

Yeah, labels. Most of my printouts that don't go to one of the electronic forms are going to a label printer. (Admittedly, often I need the labels because they contain bar codes and what I'm actually working on is the code that uses those bar codes.) Actually, for the most part I cheated with my label code--the user uses the manufacturer's label-printing program to build the label except instead of actual values they do things like %jobname%. Then they print it to a file and I use that file as a template, replacing the codes with the actual values. The guy actually using the labels sometimes has to run off several test labels to get the layout right (while everything will appear exactly where it's commanded the length changes which can cause things to overlap that didn't in the designer.)
 

rousseau

Contributor
Joined
Jun 23, 2010
Messages
12,489
So it's been nearly three years and all I've learned is a largely irrelevant technology. And with our wedding / honeymoon last year done and over with, and a bit of a lull where I don't have much on the go, I'm planning on sharpening the saw a bit.

Last year I spent a few hours getting familiar with React, but over the next number of months I'd like to dive a bit deeper into it, as well as Vue, and maybe even Node but solely out of curiosity. Moreover, I mostly want to get some significant code up to my Github account as a visual indicator that I can learn. The last major push I made to my account was a bunch of college projects in 2014, and since then I've only tinkered around a tiny bit here and there.

Having worked for a fortune 500 company since then certainly doesn't hurt, but in my current role it doesn't look like I'm doing much.
 

bigfield

the baby-eater
Joined
May 4, 2011
Messages
4,651
Location
Straya
Basic Beliefs
yeah nah
Last year I spent a few hours getting familiar with React, but over the next number of months I'd like to dive a bit deeper into it, as well as Vue, and maybe even Node but solely out of curiosity.

The hardest part of JavaScript development is tooling up an IDE and configuring an environment. It is a colossal headfuck.

Writing the actual code is quite pleasant.
 

rousseau

Contributor
Joined
Jun 23, 2010
Messages
12,489
Last year I spent a few hours getting familiar with React, but over the next number of months I'd like to dive a bit deeper into it, as well as Vue, and maybe even Node but solely out of curiosity.

The hardest part of JavaScript development is tooling up an IDE and configuring an environment. It is a colossal headfuck.

Writing the actual code is quite pleasant.

That was also my experience last year.

- Think I'll quickly fuck around with React
*wait, wtf..? Guess I need a whole afternoon to do this*

Eventually I had to set a day aside, and it was a tutorial that helped me through set up.
 

KeepTalking

Code Monkey
Joined
Jan 15, 2010
Messages
4,641
Location
St. Louis Metro East
Basic Beliefs
Atheist, Secular Humanist, Pastifarian, IPUnitard
Last year I spent a few hours getting familiar with React, but over the next number of months I'd like to dive a bit deeper into it, as well as Vue, and maybe even Node but solely out of curiosity.

The hardest part of JavaScript development is tooling up an IDE and configuring an environment. It is a colossal headfuck.

Writing the actual code is quite pleasant.

That was also my experience last year.

- Think I'll quickly fuck around with React
*wait, wtf..? Guess I need a whole afternoon to do this*

Eventually I had to set a day aside, and it was a tutorial that helped me through set up.

IDE's can certainly be a pain, but as far as jumping in and learning the basics of React a vanilla installation of VS Code should do just fine. From there, you just need to install NPM, and then run create-react-app to get to a good place to start playing with it. It really shouldn't take more than 5 or 10 minutes to get it up and running.
 

rousseau

Contributor
Joined
Jun 23, 2010
Messages
12,489
That was also my experience last year.

- Think I'll quickly fuck around with React
*wait, wtf..? Guess I need a whole afternoon to do this*

Eventually I had to set a day aside, and it was a tutorial that helped me through set up.

IDE's can certainly be a pain, but as far as jumping in and learning the basics of React a vanilla installation of VS Code should do just fine. From there, you just need to install NPM, and then run create-react-app to get to a good place to start playing with it. It really shouldn't take more than 5 or 10 minutes to get it up and running.

Indeed, the brunt of the effort I took last year was just figuring the bolded out. It didn't take long, but I actually had to engage my brain, rather than just opening up Sublime and starting to write.
 

KeepTalking

Code Monkey
Joined
Jan 15, 2010
Messages
4,641
Location
St. Louis Metro East
Basic Beliefs
Atheist, Secular Humanist, Pastifarian, IPUnitard
That was also my experience last year.

- Think I'll quickly fuck around with React
*wait, wtf..? Guess I need a whole afternoon to do this*

Eventually I had to set a day aside, and it was a tutorial that helped me through set up.

IDE's can certainly be a pain, but as far as jumping in and learning the basics of React a vanilla installation of VS Code should do just fine. From there, you just need to install NPM, and then run create-react-app to get to a good place to start playing with it. It really shouldn't take more than 5 or 10 minutes to get it up and running.

Indeed, the brunt of the effort I took last year was just figuring the bolded out. It didn't take long, but I actually had to engage my brain, rather than just opening up Sublime and starting to write.

True enough, knowing that create-react-app will save you boatloads of time, and knowing that you need NPM to run create-react-app is an essential first step that most people don't realize when starting out. I took a 4 day bootcamp course from Tyler McGinnis (he has some great courses, BTW) when I first learned React, so that was 8 hours total, but it walked you through setting up React by hand in the first two hours.
 

rousseau

Contributor
Joined
Jun 23, 2010
Messages
12,489
Reading the official React docs this afternoon and am finding them pretty good. They're also reminding me how much I miss being challenged at work. Ah well, feeding myself in retirement is probably the more critical problem.
 

rousseau

Contributor
Joined
Jun 23, 2010
Messages
12,489
I was digging through the projects I wrote in the first half of college ca 2011-2012 tonight, the first code I'd ever written. I had an idea of what I'd find, but it was still a kick going through it all. Lots of lengthy, procedural C++ programs, gargantuan functions, and severely nested loops. Hard to believe it's been eight years now.

I've passed the stage of embarrassment, though. A first step is a first step.
 

bigfield

the baby-eater
Joined
May 4, 2011
Messages
4,651
Location
Straya
Basic Beliefs
yeah nah
As a side project, I'm learning how to make a simple Android app using Android Studio and Kotlin.

Kotlin is basically what you get when someone thinks "hey, Java is a really powerful language but it's such a chore to write. What if we could make it fun, like Python?"
 

KeepTalking

Code Monkey
Joined
Jan 15, 2010
Messages
4,641
Location
St. Louis Metro East
Basic Beliefs
Atheist, Secular Humanist, Pastifarian, IPUnitard
I was digging through the projects I wrote in the first half of college ca 2011-2012 tonight, the first code I'd ever written. I had an idea of what I'd find, but it was still a kick going through it all. Lots of lengthy, procedural C++ programs, gargantuan functions, and severely nested loops. Hard to believe it's been eight years now.

I've passed the stage of embarrassment, though. A first step is a first step.

We were eliminating some tech debt on one of our projects recently, so we were reviewing some "old" ReactJS code. I saw a function that was just poorly written, even though it worked, and made a comment to the effect that whoever wrote that code had no idea what they were doing. My tech lead took a look at the diff, and noticed that I was the one who had written it about two years previous, and we had a bit of a laugh before we refactored it. We often use the identifiers "past me" and "future me" when discussing code, and say things like "past me sure was an idiot when he wrote that code", or "I wonder what future me will think of this code I just threw together".
 

rousseau

Contributor
Joined
Jun 23, 2010
Messages
12,489
I was digging through the projects I wrote in the first half of college ca 2011-2012 tonight, the first code I'd ever written. I had an idea of what I'd find, but it was still a kick going through it all. Lots of lengthy, procedural C++ programs, gargantuan functions, and severely nested loops. Hard to believe it's been eight years now.

I've passed the stage of embarrassment, though. A first step is a first step.

We were eliminating some tech debt on one of our projects recently, so we were reviewing some "old" ReactJS code. I saw a function that was just poorly written, even though it worked, and made a comment to the effect that whoever wrote that code had no idea what they were doing. My tech lead took a look at the diff, and noticed that I was the one who had written it about two years previous, and we had a bit of a laugh before we refactored it. We often use the identifiers "past me" and "future me" when discussing code, and say things like "past me sure was an idiot when he wrote that code", or "I wonder what future me will think of this code I just threw together".

I noticed it a lot when I was going through college. We programmed an enormous amount between 2011 and the end of 2014, I think everyone in the program improved rapidly. I'd easily turn my nose up at code I'd written just 4 or 5 months earlier.

These days it seems to be all about correctness. My ultimate recognition as a developer is that my code has to be tested, and work as intended. So now it's all slow and steady until the end product is right, and my code is readable / follows standards.
 

rousseau

Contributor
Joined
Jun 23, 2010
Messages
12,489
I've always said that a programming job is 95% laid-back and 5% pretty awful. And it looks like after four years I've finally been thrust into healthcare hard-mode. But after also being thrust into a senior/architect position directly out of college when I could barely code yet, for two years, this doesn't even seem too bad.

Luckily the actual programming I need to do tends to not be that difficult, and very repetitive.
 

James Brown

Veteran Member
Joined
Dec 29, 2005
Messages
3,613
Location
Texas
Basic Beliefs
Agnostic Atheist
I've been focused on learning Python.

I'm discovering that I learn more quickly if I have a project. Sure, I'll watch the little tutorial, follow along with the examples, and I won't retain a thing. What really makes me sit up are puzzles.

"Here's a 400-character-long string. Test whether it's a palindrome."

"What's the longest repeating sequence of characters in this string?"

"Calculate the mean, the median, and the average of these integers."

Etc...
 

J842P

Veteran Member
Joined
Jan 30, 2006
Messages
4,137
Location
USA, California
Basic Beliefs
godless heathen
I've been focused on learning Python.

I'm discovering that I learn more quickly if I have a project. Sure, I'll watch the little tutorial, follow along with the examples, and I won't retain a thing. What really makes me sit up are puzzles.

"Here's a 400-character-long string. Test whether it's a palindrome."

"What's the longest repeating sequence of characters in this string?"

"Calculate the mean, the median, and the average of these integers."

Etc...
If you already know another similar language, like Java, Ruby, etc or even JS, then Python is a breeze.
 

James Brown

Veteran Member
Joined
Dec 29, 2005
Messages
3,613
Location
Texas
Basic Beliefs
Agnostic Atheist
I've been focused on learning Python.

I'm discovering that I learn more quickly if I have a project. Sure, I'll watch the little tutorial, follow along with the examples, and I won't retain a thing. What really makes me sit up are puzzles.

"Here's a 400-character-long string. Test whether it's a palindrome."

"What's the longest repeating sequence of characters in this string?"

"Calculate the mean, the median, and the average of these integers."

Etc...
If you already know another similar language, like Java, Ruby, etc or even JS, then Python is a breeze.

Well, I don't know any language. I got into this by teaching myself shell scripting with Powershell. Now I'm trying to broaden my skill set for job security.
 

J842P

Veteran Member
Joined
Jan 30, 2006
Messages
4,137
Location
USA, California
Basic Beliefs
godless heathen
I've been focused on learning Python.

I'm discovering that I learn more quickly if I have a project. Sure, I'll watch the little tutorial, follow along with the examples, and I won't retain a thing. What really makes me sit up are puzzles.

"Here's a 400-character-long string. Test whether it's a palindrome."

"What's the longest repeating sequence of characters in this string?"

"Calculate the mean, the median, and the average of these integers."

Etc...
If you already know another similar language, like Java, Ruby, etc or even JS, then Python is a breeze.

Well, I don't know any language. I got into this by teaching myself shell scripting with Powershell. Now I'm trying to broaden my skill set for job security.

Ah, yes. I am unfamiliar with powershell, but from what I understand, it is a full-fledge modern language. Probably similar to Python. But yeah, probably you are essentially coming at this as a beginner. Python is a good beginner language to learn. I suggest using MOOCS.

1) The Rice University Course. It's good because you learn by making games. It has a simple GUI library and it's quite satisfying because you start with simple text-based games, move on to things like Pong, and eventually create an Asteroids clone!

https://www.coursera.org/learn/interactive-python-1

2) The MIT introductory CS course. This is an introduction to computer science not programming. But its at a relatively advanced level for an introductory course, I imagine most students taking intro to CS at MIT already are adept programmers. But from a computer science perspective it is quite good, it takes a lot from the classic textbook The Structure and Interpretation of Computer Programs
but brings it down for us mere mortals. And it uses Python instead of LISP/Scheme... so there's that.
https://www.edx.org/course/introduction-to-computer-science-and-programming-7


I think in combination these give you a great background.
 

Loren Pechtel

Super Moderator
Staff member
Joined
Sep 16, 2000
Messages
37,501
Location
Nevada
Gender
Yes
Basic Beliefs
Atheist
I've been focused on learning Python.

I'm discovering that I learn more quickly if I have a project. Sure, I'll watch the little tutorial, follow along with the examples, and I won't retain a thing. What really makes me sit up are puzzles.

"Here's a 400-character-long string. Test whether it's a palindrome."

"What's the longest repeating sequence of characters in this string?"

"Calculate the mean, the median, and the average of these integers."

Etc...

Second this. I'm a firm believer in the route to learning something in programming is to attempt to use it to accomplish something useful.
 

barbos

Contributor
Joined
Nov 12, 2005
Messages
14,581
Location
Mlky Way galaxy
Basic Beliefs
atheist
Recently I have been learning python (among other things like JS) too.
I did some stuff in python 20 years ago but it was one time stint with python and MySQL.
Python seems superficially simple and easy to start doing something. But I found that if you dig dipper it's rather difficult and very different from C++. A lot of stuff is not explicitly mentioned/explained in tutorials. For example importing modules have few things which I found unexpected and took me awhile to realize why it behaves that way.
Decorators are also unusual and combined with other usual tricks make other peoples code rather unreadable/confusing for someone who is used to C++. Dynamically typed languages are weird.
 

J842P

Veteran Member
Joined
Jan 30, 2006
Messages
4,137
Location
USA, California
Basic Beliefs
godless heathen
Recently I have been learning python (among other things like JS) too.
I did some stuff in python 20 years ago but it was one time stint with python and MySQL.
Python seems superficially simple and easy to start doing something. But I found that if you dig dipper it's rather difficult and very different from C++. A lot of stuff is not explicitly mentioned/explained in tutorials. For example importing modules have few things which I found unexpected and took me awhile to realize why it behaves that way.
Decorators are also unusual and combined with other usual tricks make other peoples code rather unreadable/confusing for someone who is used to C++. Dynamically typed languages are weird.

Yes, many fundamental aspects of python are quite different from C, C++. But there is an inherent simplicity.

Decorators aren't really that unusual. The decorator syntax:

Code:
@some_decorator
def foo(a, b):
    ...

Is equivalent to:

Code:
def foo(a, b):
    ...
foo = some_decorator(foo)

A "decorator" is simply any callable (e.g. function) that accepts a callable as an argument and returns a callable, although the @decorator syntactic sugar does not enforce that (there's one big difference between C++ and Python, Python relies on convention often). The idea is that your decorator should return the callable with "some behavior decorated on it". And there really is nothing unusual about this when functions are first-class objects.
 

barbos

Contributor
Joined
Nov 12, 2005
Messages
14,581
Location
Mlky Way galaxy
Basic Beliefs
atheist
Recently I have been learning python (among other things like JS) too.
I did some stuff in python 20 years ago but it was one time stint with python and MySQL.
Python seems superficially simple and easy to start doing something. But I found that if you dig dipper it's rather difficult and very different from C++. A lot of stuff is not explicitly mentioned/explained in tutorials. For example importing modules have few things which I found unexpected and took me awhile to realize why it behaves that way.
Decorators are also unusual and combined with other usual tricks make other peoples code rather unreadable/confusing for someone who is used to C++. Dynamically typed languages are weird.

Yes, many fundamental aspects of python are quite different from C, C++. But there is an inherent simplicity.

Decorators aren't really that unusual. The decorator syntax:

Code:
@some_decorator
def foo(a, b):
    ...

Is equivalent to:

Code:
def foo(a, b):
    ...
foo = some_decorator(foo)

A "decorator" is simply any callable (e.g. function) that accepts a callable as an argument and returns a callable, although the @decorator syntactic sugar does not enforce that (there's one big difference between C++ and Python, Python relies on convention often). The idea is that your decorator should return the callable with "some behavior decorated on it". And there really is nothing unusual about this when functions are first-class objects.
I know that now. Then there are descriptors and there is whole bunch of __something__ symbols with special meanings.
And when you see something which use all of that at the same time code becomes unreadable. Also the fact that the same thing can be done quite differently (different syntax) does not help when you are trying to learn it from scratch.
Also, dynamic typing means IDE often have no idea of the type of the object it has. I mentioned modules already, "import module" and "from module import" have not so obvious and not mentioned differences.

Also, I have a general complain about proliferation of languages. There are too many of them doing essentially the same and they tend to not die for some reason, why perl is still alive? why PHP exist? embed damn python into html and get rid of it. Then Ruby... why?
 

Jokodo

Veteran Member
Joined
Dec 29, 2010
Messages
4,653
Location
Riverside City
Basic Beliefs
humanist

fromderinside

Mazzie Daius
Joined
Oct 6, 2008
Messages
15,945
Location
Local group: Solar system: Earth: NA: US: contiguo
Basic Beliefs
optimist

lpetrich

Contributor
Joined
Jul 28, 2000
Messages
20,712
Location
Eugene, OR
Gender
Male
Basic Beliefs
Atheist
Desperate enough to have russians from Russia?
$80 per hour, I can learn COBOL in two days for that.

Bad bet. APL is much more efficient. My little brother, almost 78, up in Ilwaco WN has been replacing COBOL with APL for banks, Insurance companies, and Oil Companies for over 40 years.
APL? There's a programming language with that name, but it uses lots of extra symbols, and it is very terse. Why APL and not (say) Python?
 

Jokodo

Veteran Member
Joined
Dec 29, 2010
Messages
4,653
Location
Riverside City
Basic Beliefs
humanist
Bad bet. APL is much more efficient. My little brother, almost 78, up in Ilwaco WN has been replacing COBOL with APL for banks, Insurance companies, and Oil Companies for over 40 years.
APL? There's a programming language with that name, but it uses lots of extra symbols, and it is very terse. Why APL and not (say) Python?

Because Python was not around when New Jersey digitized their unemployment claim processing in the 1970s. They had a choice between COBOL, Lisp, ForTran, and APL, and a few more that are even more obscure today - and two of these explicitly targeted a scientific rather than administrative applications.
 

barbos

Contributor
Joined
Nov 12, 2005
Messages
14,581
Location
Mlky Way galaxy
Basic Beliefs
atheist

steve_bank

Diabetic retinopathy and poor eyesight. Typos ...
Joined
Nov 10, 2017
Messages
11,083
Location
seattle
Basic Beliefs
secular-skeptic
I’m not doing anything serious, but needed to plot for loking at math and sciene. I didn’t want to go to the trouble of installing a graphics package so I took the path of least resistance and imported to Scilab. Scilab is ok for coding but it is a slow intrpreter and the debugger is not very good.
Visual Studio is pretty good.

Sciab has a full range of 2d.3d plots abd exort functions. Easy install.

#include "steve.h"
#include <fstream>
#include <iomanip>
using namespace std;

int main()
{
ofstream testfile;
testfile.open("example.txt");
float x,y, dt,t;
dt = 0.01;
for (t = 0; t <= 1 ; t += dt) {
x = sin(_PI2 * t);
y = cos(_PI2 * t);
cout << t << setw(20) << x << setw(20) << y << "\n";
testfile << t << setw(20) << x << setw(20) << y << "\n";
}
testfile.close();
return 0;
}
//sclab
clear
[f1,err] = mopen("c:\\documents\SCILAB\example.txt","rt")
if(err < 0)then disp("file open error");end;
// -1 go to end of file
x=mfscanf(-1,f1,' %e %e %e')
// r rows c columns
[r,c] = size(x)
err = mclose("all")
if(err < 0) then disp("file close error")end;
plot2d(x(1:r,1),x(1:r,2))
g=gca()
g.x_location = "middle"
xs2png(w1,"c:\documents\scilab\plots\fig1")

fig1.png
 

steve_bank

Diabetic retinopathy and poor eyesight. Typos ...
Joined
Nov 10, 2017
Messages
11,083
Location
seattle
Basic Beliefs
secular-skeptic
A make work project to keep busy, a low pass digital filter. It us under the category of real time systems.

In a real implementation an analog to digital converter would be sampling a signal and pushing samples into a buffer the length of the number of filter coefficients. The filter has to execute and an output generated before the next input sample.

The filter is auto-regressive. At any sample n the filter operates on the sample plus the previous number of samples equal to the filter length.

There are different algorithms to generate filter coefficients. That would be a math thread.

The simulation is mot entirely accurate, it uses floating point. In a real system the output and input to analog digital converters are signed integers that limit the accuracy and resolution.



#include "steve.h""
#include <fstream>
#include <iomanip>
using namespace std;

void make_sin(float fs, double x[], double y[],int sf, double tmax, int msize) {
int i;
double dt,t;
dt = 1/fs;
t = 0;
for (i = 0; i < msize; i++) {
x = t;
y = sin(_PI2 * sf * t);
t += dt;
}
}

void fir_lp(double isig[], double osig[], double coef[], int lencoef, int lensig) {
// low pass filter
int i, j, k, n;
double acc;
double* buffer = new double[lencoef];
// initialize the input buffer
for (i = 0; i < lencoef; i++)buffer = 0;
k = 0;
for (i = 0; i < lensig; i++) {
acc = 0;
for (j = 0; j < lencoef; j++) acc += coef[j] * buffer[j]);
osig[k++] = acc; // output to digital to analog converter
//push new analog to digital converter sample onto the buffer.
for (n = 1; n < lencoef; n++)buffer[n - 1] = buffer[n];
buffer[lencoef - 1] = isig;
}
delete [] buffer;
}

int main()
{
double samp_freq,tmax;
int sig_freq, i, n, ncoef, msize;
// get filter coefficients
ifstream coeffile;
coeffile.open("coef.txt");
coeffile >> ncoef; // filter length
coeffile >> tmax; // simulation time
double* coef = new double[ncoef];
for (i = 0; i < ncoef; i++) coeffile >> coef;
coeffile.close();
sig_freq = 1; //hertz sampling frequency
samp_freq = 100; //hertz sample frequency
msize = ceil(tmax * samp_freq); //array size
double* x = new double[msize];
double* filtin = new double[msize];
double* filtout = new double[msize];
ofstream outfile;
outfile.open("lpout.txt");
make_sin(samp_freq, x, filtin, sig_freq,tmax,msize);
fir_lp(filtin, filtout, coef,ncoef,msize);
for(i=0;i < msize; i++)outfile << x << " " << filtin << " "<< filtout << "\n";
outfile.close();
delete [] x;
delete [] filtin;
delete [] filtout;
return(0);
}
 

excreationist

Married mouth-breather
Joined
Aug 29, 2000
Messages
2,160
Location
Australia
Basic Beliefs
Probably in a simulation
....
Code:
#include "steve.h""
#include <fstream>
#include <iomanip>
using namespace std;

void make_sin(float fs, double x[], double y[],int sf, double tmax, int msize) {
    int i;
    double dt,t;
    dt = 1/fs;
    t = 0;
    for (i = 0; i < msize; i++) {
        x[i] = t;
        y[i] = sin(_PI2 * sf * t);
        t += dt;
    }
}
Hi I was just testing out the code tag on your code.... it even automatically fixed all of the indentation.... which is nice....

Code:
[COLOR=#333333]int main()[/COLOR]
[COLOR=#333333]{[/COLOR]
[COLOR=#333333]double samp_freq,tmax;[/COLOR]
[COLOR=#333333]int sig_freq, i, n, ncoef, msize;[/COLOR]
[COLOR=#333333]// get filter coefficients[/COLOR]
[COLOR=#333333]ifstream coeffile;[/COLOR]
[COLOR=#333333]coeffile.open("coef.txt");[/COLOR]
[COLOR=#333333]coeffile >> ncoef; // filter length[/COLOR]
[COLOR=#333333]coeffile >> tmax; // simulation time[/COLOR]
[COLOR=#333333]double* coef = new double[ncoef];[/COLOR]
[COLOR=#333333]for (i = 0; i < ncoef; i++) coeffile >> coef[i];[/COLOR]
[COLOR=#333333]coeffile.close();[/COLOR]
[COLOR=#333333]sig_freq = 1; //hertz sampling frequency[/COLOR]
[COLOR=#333333]samp_freq = 100; //hertz sample frequency[/COLOR]
[COLOR=#333333]msize = ceil(tmax * samp_freq); //array size[/COLOR]
[COLOR=#333333]double* x = new double[msize];[/COLOR]
[COLOR=#333333]double* filtin = new double[msize];[/COLOR]
[COLOR=#333333]double* filtout = new double[msize];[/COLOR]
[COLOR=#333333]ofstream outfile;[/COLOR]
[COLOR=#333333]outfile.open("lpout.txt");[/COLOR]
[COLOR=#333333]make_sin(samp_freq, x, filtin, sig_freq,tmax,msize);[/COLOR]
[COLOR=#333333]fir_lp(filtin, filtout, coef,ncoef,msize);[/COLOR]
[COLOR=#333333]for(i=0;i < msize; i++)outfile << x[i] << " " << filtin[i] << " "<< filtout[i] << "\n";[/COLOR]
[COLOR=#333333]outfile.close();[/COLOR]
[COLOR=#333333]delete [] x;[/COLOR]
[COLOR=#333333]delete [] filtin;[/COLOR]
[COLOR=#333333]delete [] filtout;[/COLOR]
[COLOR=#333333]return(0);[/COLOR]
[COLOR=#333333]}[/COLOR]
Edit: it didn't fix the indentation for that - oh well....
 

steve_bank

Diabetic retinopathy and poor eyesight. Typos ...
Joined
Nov 10, 2017
Messages
11,083
Location
seattle
Basic Beliefs
secular-skeptic
The frequency response of the filter and the output for a sin input. The startup delay is the buffer filling up.


firmag.png

firout.png
 

steve_bank

Diabetic retinopathy and poor eyesight. Typos ...
Joined
Nov 10, 2017
Messages
11,083
Location
seattle
Basic Beliefs
secular-skeptic
The coef .txt file

33
2
-0.0086827058
0.0144278375
0.0113203161
-0.0080360033
-0.0091899954
-0.0009891973
0.0227447187
0.0087521368
-0.0368257634
-0.0127543525
0.0378075284
0.0365069835
-0.0368261824
-0.0971619203
0.0483744099
0.3187605599
0.4425552553
0.3187605599
0.0483744099
-0.0971619203
-0.0368261824
0.0365069835
0.0378075284
-0.0127543525
-0.0368257634
0.0087521368
0.0227447187
-0.0009891973
-0.0091899954
-0.0080360033
0.0113203161
0.0144278375
-0.0086827058
 

steve_bank

Diabetic retinopathy and poor eyesight. Typos ...
Joined
Nov 10, 2017
Messages
11,083
Location
seattle
Basic Beliefs
secular-skeptic
Found this on the net while looking for something else. Truncation/rounding at a decimal place. Shift left, round to get rid of unwanted digits, shift back.


double dec_places(double val, unsigned long long int n) {
unsigned long long int dp = pow(10, n);
return(round(val * dp) / dp);
}

int main() {
double xf, x = 1.123456789;
unsigned long long int n_dec = 5;
xf = dec_places(x, n_dec);
printf(" x %2.15f xf %2.15f \n", x, xf);
}
 

lpetrich

Contributor
Joined
Jul 28, 2000
Messages
20,712
Location
Eugene, OR
Gender
Male
Basic Beliefs
Atheist
That leads to think. What might be the best sorts of languages for exploratory / experimental sorts of programming?

I like computer-algebra software.

 List of computer algebra systems
 

lpetrich

Contributor
Joined
Jul 28, 2000
Messages
20,712
Location
Eugene, OR
Gender
Male
Basic Beliefs
Atheist
If you want to do number crunching with big blocks of data, here is what might be useful:

For general-purpose programming, I propose this spectrum:
  • Python - dynamic typing, easy to start with
  • Java - static typing, generics, garbage collection
  • C++ - static typing, generics, semi-explicit memory management - designed for high performance
For experimental or exploratory programming, I do NOT recommend plain C. One has to do a LOT of stuff by hand by it, and its preprocessor and its memory management are just plain bug-prone.

C++ supports several safe alternatives.

One can declare constants with "const", as a type-safe alternative to preprocessor declarations.

One can also use "const" for function args and method declarations, as a way of stating that something will not be changed.

Templates are a good type-safe alternative to preprocessor functions.

Its Standard Template Library is a set of collection classes and functions for working with them, and a nice thing about them is that one does not have to worry about memory leaks. The collections deallocate all their allocated memory when they go out of scope.

C++ now supports anonymous functions (lambdas), and that should make some uses of it a LOT easier.
 
Top Bottom