Welcome, Guest. Please login or register.
March 28, 2024, 11:42:28 am

ballp.it is the community forum for The F Plus.

You're only seeing part of the forum conversation. To see more, register for an account. This will give you read-only access to nearly all the forums.

Topic: Thread.setTitle("Programmers Anonymous");  (Read 60729 times)

Emperor Jack Chick

  • he/him
  • Ridiculist
  • Metal tyrant from hell
  • 3,193
  • 666
FOR PERFORMANCE I WRITE EVERYTHING IN ASSEMBLY


on a real note - maybe you wanna look into a linter. you're importing copy and numpy and never using either.
jack chick, July 11, 2017, 09:31:18 am

Honestly, I've never bothered with linters, although I mostly do academic programming, so.  FWIW, pylint exists, and VS Code will install it for you.  (VS Code is a super nice editor, btw.  It even works well on linux!)

Actually, kind of related to nothing but maybe useful, Spyder is a really grate python IDE for scientific computing.  I find that both Spyder and VS Code make really great python IDEs, if you're looking for one.
A Gleech that is a False Movie, July 13, 2017, 05:02:56 am


linters have been extremely useful in my professional life and have saved me a lot of time.

for python i use sublimeLint and Anaconda (cause i use sublime text fight me)

Ambious

  • Guest
Honestly, I've never bothered with linters, although I mostly do academic programming, so.  FWIW, pylint exists, and VS Code will install it for you.  (VS Code is a super nice editor, btw.  It even works well on linux!)

Actually, kind of related to nothing but maybe useful, Spyder is a really grate python IDE for scientific computing.  I find that both Spyder and VS Code make really great python IDEs, if you're looking for one.
A Gleech that is a False Movie, July 13, 2017, 05:02:56 am

+1 for VSCode and pylint

lazzer grardaion?

  • Paid
  • 703
  • 27
All this advice has been very helpful, though it does certainly make me wish I'd started learning this, like, five years ago. Anyways, I've been playing around with slightly more complicated versions of the thing I did, and it made a bunch of pretty pictures, so here you all go:





A Whirring Bone-White Gleech Peartee

A Whirring Bone-White Gleech

  • fact-lord
  • Paid
  • I was in first place, you whore!
  • 720
  • 155
for python i use sublimeLint and Anaconda (cause i use sublime text fight me)
jack chick, July 13, 2017, 09:43:16 am

How do you like Anaconda?  I've been telling students to use WinPython, but it looks like Anaconda's packaging might be even better.

Same question for Sublime.  I've never used it, I usually use gvim or VS Code, like I said.  How do you like Sublime, think it's worth trying out?  (I wonder if I could convince the department to spring for a key...)

All this advice has been very helpful, though it does certainly make me wish I'd started learning this, like, five years ago. Anyways, I've been playing around with slightly more complicated versions of the thing I did, and it made a bunch of pretty pictures, so here you all go:






LancashireMcGee, July 14, 2017, 04:31:29 pm

Very nice!  Feel like sharing the code you used to generate those, if you'd like some further pointers? =D

It reminds me of my brother's first project.  He's a math PhD.  One of the things that made him pretty excited about programming - and python in particular - was when he built a fractal viewer from scratch.
« Last Edit: July 17, 2017, 10:04:18 pm by A Gleech that is a False Movie »

Emperor Jack Chick

  • he/him
  • Ridiculist
  • Metal tyrant from hell
  • 3,193
  • 666
I mostly use anaconda for goto references regarding variable instantiation, which I'm happy with. I haven't dug into its more advanced features yet

I really like sublime for a lot of little things it does. I love that I can select multiple several different sections with a mouse and then insert/delete the same text simultaneously cutting down on problematic find/replace operations. Its search operates either with string matching or regex, which is a toggle so that you can tailor your find and replaces easily. Package control works beautifully and allows for rapid customization. I like its font scaling. its key commands make a lot more sense to me than other things (like notepad++ or pycharm).

I haven't used Atom and I"m certainly not a power user, just FYI.

Also you don't need a key, the only thing a sublime key does is stop an annoying popup from happening.

lazzer grardaion?

  • Paid
  • 703
  • 27

Very nice!  Feel like sharing the code you used to generate those, if you'd like some further pointers? =D

It reminds me of my brother's first project.  He's a math PhD.  One of the things that made him pretty excited about programming - and python in particular - was when he built a fractal viewer from scratch.
A Gleech that is a False Movie, July 17, 2017, 09:58:01 pm

Sure thing. It's basically a version of the Ising model called the Potts Model, where instead of 'up' or 'down', there are n possible states that can be thought of as evenly-spaced points on a circle, and the energy between two neighbors is determined by the cosine of the difference in angle.

# This program simulates the n-state Vector Potts model using Monte-Carlo methods

import random
import math
import matplotlib.animation as animation
import matplotlib.pyplot as plt

# This sets the number of steps per frame update.
steps = 1000

# This sets the temp of the system.
temperature = float(input('Temperature? \n'))

# This sets the number of possible states or 'directions' a cell can have.

m = int(input('Number of states? \n'))

# n sets size of the grid
n = 150

def c(x):
    return math.cos(2*math.pi*x/m)

'''
The partition function determines the probabilities of a cell picking different
states after a step. This probability of ending up in a given state is
exp(-energy/temperature)/Z, where Z is the sum of exp(-energy/temperature) over
all possible states for the cell.

Since there is a finite number of possible energies for a given cell, these are
computed beforehand.
'''

partsgrid = [[[[[math.exp((c(a-b)+c(a-d)+c(a-e)+c(a-f))/temperature)
                  for a in range( 0 , m ) ] for b in range( 0 , m ) ] for d in range( 0 , m ) ]
                  for e in range( 0 , m ) ] for f in range( 0 , m ) ]
zlist = [[[[sum(partsgrid[f][e][d][b][a] for a in range( 0 , m ))
                  for b in range( 0 , m ) ] for d in range( 0 , m ) ] for e in range( 0 , m ) ]
                  for f in range( 0 , m ) ]

# The grid is randomly laid out with the m possible directions.
g = [[random.randint( 0 , m - 1 ) for i in range( 1 , n + 1 )] for j in range( 1 , n + 1 )]

def pottsupdate(data):
    global g
    for q in range(1, steps):

        # Random locations on the grid are then selected.
        i = random.randint(-1, n - 2)
        j = random.randint(-1, n - 2)

        '''
        Cells randomly choose a new state, with probabilities determined by the
        relative weights exp(-energy/temperature)/Z. This is done by making a
        list of the partial sums of these probabilities, and then counting how
        many of those partial sums are less than a randomly chosen number .
        '''

        partstemp = [partsgrid[g[i+1][j]][g[i-1][j]][g[i][j+1]][g[i][j-1]][s] for s in range(0,m)]
        energyspace = [sum(partstemp[p] for p in range(0,s)) / zlist[g[i][j-1]][g[i][j+1]][g[i-1][j]][g[i+1][j]] for s in range(1,m)]
        k = random.random()
        g[i][j] = len([a for a in energyspace if a < k])
    mat.set_data(g)
    return [mat]

# The figure and axes are initialized, and then told to update based on the
# rules defined above.

fig, ax = plt.subplots()
mat = ax.matshow(g)
ani = animation.FuncAnimation(fig, pottsupdate, interval = 1, blit = True)
plt.show()


Fractal viewer might be a fun next project. Waaaaay back in highschool I programmed a Mandelbrot set grapher on my TI-83. It worked great, but it took like 2 hours to run.
« Last Edit: July 18, 2017, 05:15:01 pm by LancashireMcGee »

Ambious

  • Guest

junior associate faguar

  • Frankly, an unreasonable level of uguu~
  • Paid
  • 446
  • -44
Thread.setTitle("Programmers Anonymous"); #82

Emperor Jack Chick

  • he/him
  • Ridiculist
  • Metal tyrant from hell
  • 3,193
  • 666
Thread.setTitle("Programmers Anonymous"); #83

journeyman faguar, October 08, 2017, 11:07:08 pm

legit buying that mug for my coworker.
junior associate faguar

Schumin Capote

  • Paid
  • Nice to see you, to see you nice.
    • 310
    • 14
Thread.setTitle("Programmers Anonymous"); #84
We have a rotating role where each sprint, we assign one developer as the "bug hunter." Unfortunately, the rest of the team doesn't seem to be aware of the true meaning of that phrase, so I do my best not to laugh whenever they mention it. Somehow, I don't think I'll be sending them a link to the "Raw Top Breeding Zone" episode of Lou Read's the Internet for You.

lazzer grardaion?

  • Paid
  • 703
  • 27
Thread.setTitle("Programmers Anonymous"); #85
We have a rotating role where each sprint, we assign one developer as the "bug hunter." Unfortunately, the rest of the team doesn't seem to be aware of the true meaning of that phrase, so I do my best not to laugh whenever they mention it. Somehow, I don't think I'll be sending them a link to the "Raw Top Breeding Zone" episode of Lou Read's the Internet for You.
Schumin Capote, October 11, 2017, 02:49:05 am




I can't help but feel that programmers are more likely to be familiar with sci-fi action classics than horrifying internet subcultures. Either that or I've been interpreting Aliens completely wrong all these years.
chai tea latte Schumin Capote

A Whirring Bone-White Gleech

  • fact-lord
  • Paid
  • I was in first place, you whore!
  • 720
  • 155
Thread.setTitle("Programmers Anonymous"); #86
Why is java so goddamned over-engineered?  Why do five different classes have to interact to achieve absolutely anything?  Why do they provide four competing ways, each composed of 50 classes, to do absolutely everything?  Why is opening a file and writing to it a multi-step process?  WHO DESIGNED THIS NIGHTMARE?

junior associate faguar

  • Frankly, an unreasonable level of uguu~
  • Paid
  • 446
  • -44
Thread.setTitle("Programmers Anonymous"); #87
WHO DESIGNED THIS NIGHTMARE?
A Whirring, Bone-White Gleech, October 12, 2017, 06:13:41 pm

You've found the problem. No one designed it, many people designed it all at once, and whenever they disagreed they just made it more complicated to fix the problem.

See also: C++.
Gyro

A Whirring Bone-White Gleech

  • fact-lord
  • Paid
  • I was in first place, you whore!
  • 720
  • 155
Thread.setTitle("Programmers Anonymous"); #88
WHO DESIGNED THIS NIGHTMARE?
A Whirring, Bone-White Gleech, October 12, 2017, 06:13:41 pm

You've found the problem. No one designed it, many people designed it all at once, and whenever they disagreed they just made it more complicated to fix the problem.

See also: C++.
journeyman faguar, October 12, 2017, 06:24:20 pm

Consider the following:

def write(points, fname):
    with open(fname, "w") as outfile:
        for p in points:
            outfile.write("<{}, {}>\n".format(p.x, p.y))
Wow, that's concise, innit?  If you aren't familiar with python, the with-block will guarantee that my file gets closed when that block is exited, even if an exception is thrown, without me having to do anything.  Note also that open() just kicks up a file-like object with a nice, tractable write method.

Now let's see that in C++.
void write(const std::vector<Point> & points, const std::string & fname) {
    std::ofstream outfile(fname);

    for(auto p: points) {
        outfile << "<" << p.x << ", " << p.y << ">" << std::endl;
    }
}
OK, so, unsurprisingly, it's a little uglier.  Note the use of auto in that for-loop: type-declarations can get really ugly when you're using C++ templated containers, especially when it's a const-reference-to something.  Auto doesn't really make that not true, it just makes it not my problem, which is good enough.

It's not obvious, but this also guaranteeably closes my output file, even if an exception is thrown.  The reason why would take some explaining, but it's true.

Now let's look at this trivial things in Java.
    public static void write(Vector<Point> points, String fname) throws IOException {
        BufferedWriter outbuffer = null;
        try {
            FileWriter outfile = new FileWriter(fname);
            outbuffer = new BufferedWriter(outfile);
           
            for (Point p: points) {
                outbuffer.write("<" + p.x + ", " + p.y + ">\n");
            }
        } finally {
            if (outbuffer != null) {
                outbuffer.close();
            }
        }
    }

I have so many questions.  What are the responsibilities of those two classes, FileWriter and BufferedWriter?  Doesn't FileWriter already have a write() method?  Do I need the BufferedWriter?  Is it providing buffering for non-buffered output?  Why are those responsibilities split?  Why doesn't the FileWriter just buffer by default and provide a flush() method like any reasonable implementation would?  Why is this my problem as a user?

Why do I need a try/catch block if I marked the function as throwing?  Well, that's for the finally block, to make sure the file is closed.  But again, why the fuck is that even my problem?  Why doesn't Java have a with() block or similar construct?  Why does the close method itself throw an IOException?  What the fuck am I supposed to do if that happens?  Actually handling that exception would make my code way more complicated, so I just gave up and marked the function as throwing.  Why is the try block out-of-scope in the finally block?  That makes using it for its intended purpose more annoying, to no benefit.

Many of these complaints are small things, but they add up, and they add up more in non-trivial cases.

My answer to all these questions: the java developers are a) way, way too conservative, refusing to implement features (like with blocks) that are common-place in every other language in 2017, or b) they're way to enamored with the whole "a clean object model as the only metaphor for programming, period" ethos that sort of defined the early Java community, or c) they're lazy idiots and just don't give a fuck.  Or maybe some combination of all three.
Gyro junior associate faguar
« Last Edit: October 23, 2017, 04:47:47 pm by A Whirring, Bone-White Gleech »

Emperor Jack Chick

  • he/him
  • Ridiculist
  • Metal tyrant from hell
  • 3,193
  • 666
Thread.setTitle("Programmers Anonymous"); #89

journeyman faguar, October 08, 2017, 11:07:08 pm

legit buying that mug for my coworker.
jack chick, October 09, 2017, 10:35:07 am

UPDATE: the mug has arrived.