Skip to content

u/thestoicattack

In this archive from Nov 2013 to Jun 2018

0
posts
53
comments
0
media
313
score

Top comments

C++ seems like a less than ideal language for this, but here are some comments:

main.cpp:

totally unnecessary heap allocations of your Pacmanpp objects. They should just be on the stack:

Pacmanpp pacman;
pacman.update();

But if you insist on heap allocation, for the love of god use a smart pointer, as auto pacman = std::make_unique<Pacmanpp>();. This is guaranteed to free the object for you when it goes out of scope. In general, raw new/delete are bad ideas in new, modern C++.

Don't use std::list! It's a horrible inefficient linked list. Just use std::vector. Also, you don't need to explicitly iterate (L39,L58), since the vector constructor can take two iterators:

std::vector<std::string> packages(args + 2, args + arg);
pacman.search(packages);

L43: explicit iterators are disfavored. Prefer for (const auto& s : packages).

Also, strncmp is a pain in the ass. You can compare cstrings to string literals (""s) using ==.

Package.cpp:

complete overusage of this pointer which is not typically necessary. Example: prefer std::string Package::getName() { return name; }.

Lack of const on methods that should be const (don't change the underlying object. checkIfGit, getName, etc. should be marked const.

Default constructor/destructor are not necessary. Destructor especially, but if you need the no-arg constructor in particular for some reason, prefer Package() = default;.

Pacmanpp.cpp:

populateList: inconsistent use of sudo when messing around with that tempfile. In fact, why use a tempfile at all, if you're so system-happy? You could fork/exec and pipe the child process's stdout directly to you. Also, the system command has an extra echo and subshell that aren't necessary but will just fuck up your whitespace. Also, running this method multiple times will duplicate the packages again. It's probably better to return a new vector here, or else remember to clear the member variable before you do this.

curlPackages: L273: more explicit iteration. Easier:

for (const auto& p : packages) {
  curlOne(multi, p.getURL(), p.PKGBUILD);
}

removeDuplicates is really just two calls from <algorithm>:

void removeDuplicates(std::vector<Package>& v) {
  std::sort(
      v.begin(),
      v.end(),
      [](const auto& a, const auto& b) {
        return a.getName() < b.getName();
      });
  auto it = std::unique(
      v.begin(),
      v.end(),
      [](const auto& a, const auto& b) {
        return a.getName == b.getName();
      });
  v.erase(it, v.end());
}

Also, useless comment. Also, could be made static since it doesn't need any member variables. Could even be a free function.

printSearchResults should take a constref, not a vector by value. Way overdone error checking on std::stoi num, why not std::cin >> num and just check that return value? Way easier. L402: more explicit iteration. Also, could be static, again.

parsePACMAN: holy hell, use a library. libxml2 would work. Some for parseAUR.

Sudo-related stuff: This seems like a huge hack. Is it really necessary? Why not run the whole thing under sudo? Sub-threads should also be privileged, right?

Anyway, this is just off the top of my head, there's probably more.

74 points

Subreddits

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.