Programming thread

Finally, some useful CS research.
It does sound more useful than everything else out there:
2023-02-13_10-19.png
 
The research is no good because it doesn't consider time. Consider this alternative hypothesis:
"Swearing in code was more acceptable in the 80s and any code that lasted from then long enough to make it to Github has likely been worked on and improved more than some newly written code."
I think this is pretty much it. All those ancient Linux programs (including the kernel!) have very colorful language in them.

Also I wonder if they bothered controlling for duplicate code. Anything based on the Quake 3 engine on github is going to have Carmack's //what the fuck? in it.
 
The research is no good because it doesn't consider time. Consider this alternative hypothesis:
"Swearing in code was more acceptable in the 80s and any code that lasted from then long enough to make it to Github has likely been worked on and improved more than some newly written code."

A better approach might have been to look at repos where a swear word was checked in sometime in the past year (and not part of a bulk migration to Git).
I also think the hypothesis is a little hasty. Perhaps the perceived hostility of a project which allows swearing and otherwise "unprofessional" communication acts as a gatekeeping mechanism against less confident developers.

There's more to explore here. If someone wants some low hanging fruit, I wonder what applying their methodology to the history of Linux kernel contributions would show. Has code quality significantly dipped after Linus cucked out and CoC'd up?

Edit: To be fair, it is just a bachelor's thesis. Hopefully this is the beginnings of a promising academic career
 
Last edited:
Edit: To be fair, it is just a bachelor's thesis. Hopefully this is the beginnings of a promising academic career
Yeah, it's impressive for an undergrad.

I do have a bit of a problem with the method of grabbing C and C++ code from github projects, throwing it into SoftWipe (it compiles and executes it) to check its runtime quality.

It was all run on the cloud but goddamn there are probably rootkits competing for dominance on those servers.
 
  • Agree
Reactions: Agent Sandoval
//very autistic

I've been trying to teach myself python as a first language. I figured the best way to learn quicker would be to give myself a goal to work towards, and I settled on a program that would necessitate some technical knowledge in order to split strings in a certain way. Behold, SNEEDIFIER
Python:
vowels = ('aeiouyAEIOUY')
def splitter(i):
    x = 1
    for n in i:
        if i[x] in vowels:
            return x
        else:
            x += 1
name = input('Enter Name: ')
x = splitter(name)
print(f"{name}'s F{name[x:]} and S{name[x:]}.")
This took an embarrassing amount of time. But I am now confident now in my understanding of for loops, so I guess it wasn't for nothing. There's probably a better way to do this, so let me know if there is, but I think this is reasonably concise. At least compared to...

the old version:
Python:
name = input('Enter Name: ')
name = name.lower()
name_title = name.title()
vowels = ['a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y']
if name[0] in vowels:
    print(name_title + '\'s ' + 'F' + name[0:] + ' and ' 'S' + name[0:])
elif name[1] in vowels:
    print(name_title + '\'s ' + 'F' + name[1:] + ' and ' 'S' + name[1:])
elif name[2] in vowels:
    print(name_title + '\'s ' + 'F' + name[2:] + ' and ' 'S' + name[2:])
else:
    print(name_title + '\'s ' + 'F' + name[3:] + ' and ' 'S' + name[3:])
it was seriously clunky.

mad libs edition!
Python:
def splitter(i):
    x = 1
    for n in i:
        if i[x] in vowels:
            return x
        else:
            x += 1
vowels = ('aeiouyAEIOUY')
print('''
 ▄▀▀▄ ▄▀▄  ▄▀▀█▄   ▄▀▀█▄▄       ▄▀▀▀▀▄     ▄▀▀█▀▄    ▄▀▀█▄▄   ▄▀▀▀▀▄
█  █ ▀  █ ▐ ▄▀ ▀▄ █ ▄▀   █     █    █     █   █  █  ▐ ▄▀   █ █ █   ▐
▐  █    █   █▄▄▄█ ▐ █    █     ▐    █     ▐   █  ▐    █▄▄▄▀     ▀▄
  █    █   ▄▀   █   █    █         █          █       █   █  ▀▄   █
▄▀   ▄▀   █   ▄▀   ▄▀▄▄▄▄▀       ▄▀▄▄▄▄▄▄▀ ▄▀▀▀▀▀▄   ▄▀▄▄▄▀   █▀▀▀
█    █    ▐   ▐   █     ▐        █        █       █ █    ▐    ▐
▐    ▐            ▐              ▐        ▐       ▐ ▐
''')
name = input('Enter a name: ')
name2 = input('One more name: ')
x = splitter(name)
y = splitter(name2)
print(f'''
The sign is a subtle joke.
The shop is called "{name}'s F{name[x:]} & S{name[x:]}", where f{name[x:]} and s{name[x:]} both end in the sound "-{name[x:]}", thus rhyming with the name of the owner, {name}.
The sign says that the shop was "Formerly {name2}'s", implying that the two words beginning with "F" and "S" would have ended with "-{name2[y:]}", rhyming with "{name2}".
So, when {name2} owned the shop, it would have been called "{name2}'s F{name2[y:]} and S{name2[y:]}".
''')
print('Thank you for playing!')
 
I've been trying to teach myself python as a first language.
Well done. Here's some perhaps unwanted code review (in the comments):
Python:
# No need for parentheses here, you're assigning vowels as a string.
vowels = ('aeiouyAEIOUY')

def splitter(i):
    # No need to manually keep a loop index.
    x = 1

    # Good style to loop directly over the input, but `n` is unused.
    # There is a subtle bug: the loop will run len(i) times, but as you
    # set x to 1 initially, you want it to run len(i) - 1 times. If there are
    # no vowels in the input, you'll get an IndexError.
    for n in i:
        # Good style to use the `in` operator to check membership.
        if i[x] in vowels:
            return x
        else:
            # Here you're manually incrementing the loop index.
            x += 1

name = input('Enter Name: ')
x = splitter(name)
# Good style to use f-strings and idiomatic slicing.
print(f"{name}'s F{name[x:]} and S{name[x:]}.")

Most of this comes down to Python having affordances for things you might have to do more manually in other languages. Here are some alternative versions of your splitter function that show different levels of abstraction.
Python:
def splitter_g1(string):
    # Loop over integers 1 through len(i)
    for index in range(1, len(string) + 1):
        if string[index] in vowels:
            return index


def splitter_g2(string):
    # Loop over (index, character) pairs.
    # enumerate takes an iterable and returns each element with its index.
    # By default it starts at 0.
    for index, character in enumerate(string[1:], start=1):
        if character in vowels:
            return index


def splitter_g3(string):
    for index, character in enumerate(string[1:], start=1):
        if character in vowels:
            # Return the sliced string directly.
            return string[index:]

The advantage of looping directly over an iterable, as opposed to indexing into the iterable, is that not every iterable in Python supports indexing - they might compute the values on demand, for example. This is true for the return type of enumerate:
Python:
>>> enumerate("abc")[1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'enumerate' object is not subscriptable
>>> list(enumerate("abc"))[1]
(1, 'b')
 
Last edited:
Python:
vowels = ('aeiouyAEIOUY')
def splitter(i):
    x = 1
    for n in i:
        if i[x] in vowels:
            return x
        else:
            x += 1
name = input('Enter Name: ')
x = splitter(name)
print(f"{name}'s F{name[x:]} and S{name[x:]}.")

the old version:
Python:
name = input('Enter Name: ')
name = name.lower()
name_title = name.title()
vowels = ['a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y']
if name[0] in vowels:
    print(name_title + '\'s ' + 'F' + name[0:] + ' and ' 'S' + name[0:])
elif name[1] in vowels:
    print(name_title + '\'s ' + 'F' + name[1:] + ' and ' 'S' + name[1:])
elif name[2] in vowels:
    print(name_title + '\'s ' + 'F' + name[2:] + ' and ' 'S' + name[2:])
else:
    print(name_title + '\'s ' + 'F' + name[3:] + ' and ' 'S' + name[3:])
it was seriously clunky.
Geranium already covered the most important topics, but I've got another couple of points that you may want to take into account for further improvement.

Python:
# In your first attempt you used these methods
# to give the name proper capitalization
name = name.lower()
name_title = name.title()

# In case of the user inputting a name like "cHuCk" you may want
# to get this re-implemented this.

# As an added bonus this would allow you to reduce your set of 
# letters to only include the lowercase vowels.
vowels = 'aeiouy' 

# The indexing issue Geranium mentioned aside. Starting at index
# one means you skip the first letter of the name.
x = 1
for n in i:
    if i[x] in vowels:
        return x
    else:
        x += 1
# This works fine for names like 'Chuck' and 'Sneed', but what happens
# when the user inputs a name like 'Aron' or 'Ellen'?
 
Well done. Here's some perhaps unwanted code review (in the comments):
Absolutely welcome, I love how simple it is with enumerate! Very insightful.
# The indexing issue Geranium mentioned aside. Starting at index
# one means you skip the first letter of the name.
x = 1
for n in i:
if i[x] in vowels:
return x
else:
x += 1
# This works fine for names like 'Chuck' and 'Sneed', but what happens
# when the user inputs a name like 'Aron' or 'Ellen'?
[/CODE]
Yeah, the old code accounted for names that started with vowels but doing that when I ran the mad libs program made the output include "both end in the sound -{full uncut name}" which looked weird to me, but accounting for the first letter does make better sounding "F{eed} and S{eed}" in that case. I did just totally forget to reimplement the capitalization stuff, though. Thanks!
 
My favorite failing test cases are those where it's the test that's wrong.
Way back when in university there was one Prof who published the tests he graded with along with his assignments, but wouldn't tell you the expected output. Sometimes you needed to hand in code that crashed the tests because the tests misused the program as assigned.
No other Prof prepared me more for coding in the real world.
 
I'm trying to learn how to program using Java, and right now working on understanding how to organize classes like a sane, intelligent person who has a clue what they're doing. If my program is going to create users, maybe it should be able to search current users to make sure the user name isn't already in use. Seems easy right? Oh, fuck, not really and I spend an embarrassingly long time failing before just iterating through the hashmap. Doesn't matter if it's slow or inefficient, because in a real world situation this would be a database, right?
Java:
package mypackage;

import java.util.HashMap;
import java.util.Map;

public class MyRepository {
    private Map<Integer, User> myRepo = new HashMap<>();
 
    // CRUD methods
 
    protected String getUserName(int i) {
        return myRepo.get(i).getName();
        }
    }
}

package mypackage;

public class MyService {
    private myRepo repository;

    public myService(myRepo repository) {
        this.repository = repository;
    }
 
    public boolean nameInUse(String name) {
        boolean found = false;
        for (Integer key : repository.keySet()) {
            int i = Integer.parseInt(key.toString());
            if (getUserName(i).equals(name)) {
                found = true;
                return found;
            }
        }
        return found;
    }
}

Oh, fuck, I can't access keySet()? What? I... what? It's a method that hashmaps have. Why does it work myRepository class, but not when creating an instance and invoking it in myService? So after another embarrassingly long period I try:

Java:
package mypackage;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MyRepository {
    private Map<Integer, User> myRepo = new HashMap<>();
 
    // CRUD methods
 
    protected String getUserName(int i) {
        return myRepo.get(i).getName();
        }
 
    protected Set<Integer> keySet() {
        return this.myRepo.keySet();
        }
    }
}

Now it works and I discover two things:
1: what writing an API actually is/means and why you separate classes into different layers like POJO, repository, service, and presentation.

2: I am the biggest fucking retard the world has ever known because every 12-14 year old in their computer class figures this out right away.
 
Last edited:
Doesn't matter if it's slow or inefficient, because in a real world situation this would be a database, right?
Yes, unless for some reason to you hate yourself and want to reinvent the wheel. This is a good opportunity to see if you can come up with a fast solution to the problem though. Always worth seeing if you can improve you initial solution.

I am the biggest fucking retard the world has ever known because every 12-14 year old in their computer class figures this out right away.
You're learning don't feel too bad. If you're making progress and gaining new knowledge you're on the right track. It would be worth reading about software development patterns when you get a chance, because there's more than a few.

Understanding that we're working with some very basic code here, this might be of interest to you, you can loop over your users map a lot easier using `entrySet`. Don't treat this as good code, it's just something that immediately stood out to me.

Code:
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.lang.Integer;

class User {
    private String name;
 
    public User(String name){
        this.name = name;
    }
 
    public String getName(){
        return this.name;
    }
}

class UserDemo {
    private static Map<Integer, User> users = new HashMap<>();
 
    public static void main(String[] args) {
        users.put(1, new User("Mike"));
        users.put(2, new User("Bob"));
        users.put(3, new User("Billy"));
    
        boolean found = false;
    
        for (Entry<Integer, User> entry : users.entrySet()) {
            if (entry.getValue().getName().equals("Bob")) {
                found = true;
                break;
            }
        }
    
        System.out.println(found);
    }
}
 
Last edited:
Back