/r/learnprogramming
A subreddit for all questions related to programming in any language.
If you need help debugging, you must include:
See debugging question guidelines for more info.
Many conceptual questions have already been asked and answered. Read our FAQ and search old posts before asking your question. If your question is similar to one in the FAQ, explain how it's different.
See conceptual questions guidelines for more info.
Follow reddiquette: behave professionally and civilly at all times. Communicate to others the same way you would at your workplace. Disagreement and technical critiques are ok, but personal attacks are not.
Abusive, racist, or derogatory comments are absolutely not tolerated.
See our policies on acceptable speech and conduct for more details.
When posting some resource or tutorial you've made, you must follow our self-promotion policies.
In short, your posting history should not be predominantly self-promotional and your resource should be high-quality and complete. Your post should not "feel spammy".
Distinguishing between tasteless and tasteful self-promotion is inherently subjective. When in doubt, message the mods and ask them to review your post.
Self promotion from first time posters without prior participation in the subreddit is explicitly forbidden.
Do not post questions that are completely unrelated to programming, software engineering, and related fields. Tech support and hardware recommendation questions count as "completely unrelated".
Questions that straddle the line between learning programming and learning other tech topics are ok: we don't expect beginners to know how exactly to categorize their question.
See our policies on allowed topics for more details.
Do not post questions that are an exact duplicate of something already answered in the FAQ.
If your question is similar to an existing FAQ question, you MUST cite which part of the FAQ you looked at and what exactly you want clarification on.
Do not delete your post! Your problem may be solved, but others who have similar problems in the future could benefit from the solution/discussion in the thread.
Use the "solved" flair instead.
Do not request reviews for, promote, or showcase some app or website you've written. This is a subreddit for learning programming, not a "critique my project" or "advertise my project" subreddit.
Asking for code reviews is ok as long as you follow the relevant policies. In short, link to only your code and be specific about what you want feedback on. Do not include a link to a final product or to a demo in your post.
You may not ask for or offer payment of any kind (monetary or otherwise) when giving or receiving help.
In particular, it is not appropriate to offer a reward, bounty, or bribe to try and expedite answers to your question, nor is it appropriate to offer to pay somebody to do your work or homework for you.
All links must link directly to the destination page. Do not use URL shorteners, referral links or click-trackers. Do not link to some intermediary page that contains mostly only a link to the actual page and no additional value.
For example, linking to some tweet or some half-hearted blog post which links to the page is not ok; but linking to a tweet with interesting replies or to a blog post that does some extra analysis is.
Udemy coupon links are ok: the discount adds "additional value".
Do not ask for help doing anything illegal or unethical. Do not suggest or help somebody do something illegal or unethical.
This includes piracy: asking for or posting links to pirated material is strictly forbidden and can result in an instant and permanent ban.
Trying to circumvent the terms of services of a website also counts as unethical behavior.
Do not ask for or post a complete solution to a problem.
When working on a problem, try solving it on your own first and ask for help on specific parts you're stuck with.
If you're helping someone, focus on helping OP make forward progress: link to docs, unblock misconceptions, give examples, teach general techniques, ask leading questions, give hints, but no direct solutions.
See our guidelines on offering help for more details.
Ask your questions right here in the open subreddit. Show what you have tried and tell us exactly where you got stuck.
We want to keep all discussion inside the open subreddit so that more people can chime in and help as well as benefit from the help given.
We also do not encourage help via DM for the same reasons - that more people can benefit
Do not ask easily googleable questions or questions that are covered in the documentation.
This subreddit is not a proxy for documentation or google.
We do require effort and demonstration of effort.
This includes "how do I?" questions
Such posts/comments will be removed without warning and the poster of ai generated content will be instantly banned.
/r/learnprogramming
Give me some examples of how "the Builder Design Pattern" has been used in practice in previous projects on which you have worked.
Hey Everyone,
As the title states, what is the best course/program/book to learn Python? I graduated with a B.S. in Management Info. Systems, but given the current job market, I’d like to expand my skills. I’d like to preface though that coding/programming is something I extremely struggled with in school and never found it interesting or enjoyed doing.
However, as time passes by, Python & R are becoming much more frequent and given my age, 27, I feel I’m falling behind. Alternatively, I’d like to find a role where it’s not as needed.
I found the “The Complete Python Bootcamp From Zero to Hero in Python” on Udemy and University of Helsinki - MOOC 2023.
Are there any alternatives?
Thanks in advance!
I'm creating a Wordle clone with a high contrast/dark mode option for those who are colorblind for a class project. I am having a hard time getting the tiles on the board with the letters to change the background colors to mark if a letter is in the right place or not.
To clarify, the colors change in light mode but they don't change when I toggle dark mode. I think the problem is with CSS however I included my JS code and HTML along with the CSS.
CSS/* Common styles for both modes */
body {
font-family: Arial, Helvetica, sans-serif;
text-align: center;
}
#title {
font-size: 36px;
font-weight: bold;
letter-spacing: 2px;
}
#board {
width: 350px;
height: 420px;
margin: 0 auto;
margin-top: 3px;
display: flex;
flex-wrap: wrap;
}
.tile {
/* Box */
border: 2px solid lightgray;
width: 60px;
height: 60px;
margin: 2.5px;
/* Text */
color: black;
font-size: 36px;
font-weight: bold;
display: flex;
justify-content: center;
align-items: center;
}
.keyboard-row {
width: 400px;
margin: 0 auto;
display: flex;
flex-wrap: wrap;
}
.key-tile {
width: 36px;
height: 40px;
margin: 1px;
border: 1px solid lightgray;
/* Text */
font-size: 20px;
font-weight: bold;
display: flex;
justify-content: center;
align-items: center;
}
.enter-key-tile {
width: 76px;
height: 40px;
margin: 1px;
border: 1px solid lightgray;
/* Text */
font-size: 20px;
font-weight: bold;
display: flex;
justify-content: center;
align-items: center;
}
/* Normal Mode Styles */
body.light-mode {
background-color: #ffffff;
color: #000000;
}
.correct {
background-color: #6AAA64;
color: white;
border-color: white;
}
.present {
background-color: #C9B458;
color: white;
border-color: white;
}
.absent {
background-color: #787C7E;
color: white;
border-color: white;
}
/* Dark Mode Styles */
body.dark-mode hr {
border-color: #ffffff;
}
body.dark-mode
{ text-color: #f4f4f4;
background-color: #000000;
color: #ffffff;
}
body.dark-mode
.enter-key-tile {
border-color: #ffffff;
}
.correct {
background-color: #7dcfff;
color: white;
border-color: white;
}
.present {
background-color: #ff6f00;
color: rgb(255, 255, 255);
border-color: white;
}
.absent {
background-color: #787C7E;
color: white;
border-color: white;
}
body.dark-mode #board .tile {
background-color: #707070;
}
body.dark-mode .correct {
background-color: #7dcfff;
}
body.dark-mode .present {
background-color: #ff6f00;
}
body.dark-mode .absent {
background-color: #777;
HTML
<html lang="en">
<head>
<title>Wordle</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="wordle.css">
<script src="wordle.js"></script>
<style>
#toggleDarkModeBtn {
background-color: #333;
color: white;
padding: 10px;
cursor: pointer;
border: none;
border-radius: 5px;
}
</style>
</head>
<body>
<h1 id="title">Wordle</h1>
<hr>
<br>
<div id="board">
</div>
<br>
<h1 id="answer"></h1>
<!-- Dark Mode Button -->
<button id="toggleDarkModeBtn">Toggle Dark Mode</button>
<script>
document.addEventListener("DOMContentLoaded", function () {
var toggleDarkModeBtn = document.getElementById("toggleDarkModeBtn");
toggleDarkModeBtn.addEventListener("click", function () {
document.body.classList.toggle("dark-mode");
});
});
</script>
</body>
</html>
Java scriptvar height = 6;
//number of guesses
var width = 5;
//length of the word
var row = 0;
//current guess (attempt #)
var col = 0;
//current letter for that attempt
var gameOver = false;
var wordList = ["cigar", "shave"]
var guessList = ["aahed", "aalii","zymic"];
guessList = guessList.concat(wordList);
var word = wordList[Math.floor(Math.random() * wordList.length)].toUpperCase();
console.log(word);
window.onload = function () {
initialize();
};
function initialize() {
// crating the game board
for (let r = 0; r < height; r++) {
for (let c = 0; c < width; c++) {
let tile = document.createElement("span");
tile.id = r.toString() + "-" + c.toString();
tile.classList.add("tile");
tile.innerText = "";
document.getElementById("board").appendChild(tile);
}
}
// creating the key board
let keyboard = [
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
["A", "S", "D", "F", "G", "H", "J", "K", "L", " "],
["Enter", "Z", "X", "C", "V", "B", "N", "M", "⌫"],
];
for (let i = 0; i < keyboard.length; i++) {
let currRow = keyboard[i];
let keyboardRow = document.createElement("div");
keyboardRow.classList.add("keyboard-row");
for (let j = 0; j < currRow.length; j++) {
let keyTile = document.createElement("div");
let key = currRow[j];
keyTile.innerText = key;
if (key == "Enter") {
keyTile.id = "Enter";
} else if (key == "⌫") {
keyTile.id = "Backspace";
} else if ("A" <= key && key <= "Z") {
keyTile.id = "Key" + key;
}
keyTile.addEventListener("click", processKey);
if (key == "Enter") {
keyTile.classList.add("enter-key-tile");
} else {
keyTile.classList.add("key-tile");
}
keyboardRow.appendChild(keyTile);
}
document.body.appendChild(keyboardRow);
}
}
document.addEventListener("keyup", (e) => {
processInput(e);
});
// Apply initial mode
applyMode();
function applyMode() {
const body = document.body;
// Check if dark mode is active
const isDarkMode = body.classList.contains("dark-mode");
const isHighContrast = body.classList.contains("high-contrast");
// Apply styles based on the mode
if (isDarkMode) {
applyDarkModeStyles();
} else if (isHighContrast) {
applyHighContrastStyles();
} else {
applyLightModeStyles();
}
}
function applyDarkModeStyles() {
// Adjust styles for dark mode
body.style.backgroundColor = "#1a1a1a";
body.style.color = "#ffffff";
// Example: Update tile styles
const tiles = document.querySelectorAll(".tile");
tiles.forEach(tile => {
tile.style.borderColor = "#ffffff";
tile.style.backgroundColor = "#333333";
tile.style.color = "#ffffff";
});
}
function applyHighContrastStyles() {
// Adjust styles for high contrast mode
body.style.filter = "invert(1)";
// Example: Update tile styles
const tiles = document.querySelectorAll(".tile");
tiles.forEach(tile => {
tile.style.borderColor = "#000000";
tile.style.backgroundColor = "#ffffff";
tile.style.color = "#000000";
});
}
function applyLightModeStyles() {
// Adjust styles for light mode
body.style.backgroundColor = "#ffffff";
body.style.color = "#000000";
// Example: Update tile styles
const tiles = document.querySelectorAll(".tile");
tiles.forEach(tile => {
tile.style.borderColor = "lightgray";
tile.style.backgroundColor = "#ffffff";
tile.style.color = "#000000";
});
}
function processKey() {
const e = {
code: this.id,
};
processInput(e);
}
function processInput(e) {
if (gameOver) {
return;
}
if ("KeyA" <= e.code && e.code <= "KeyZ") {
if (col < width) {
let currTile = document.getElementById(row.toString() + '-' + col.toString());
if (currTile.innerText == "") {
currTile.innerText = e.code[3];
col += 1;
}
}
} else if (e.code == "Backspace") {
if (0 < col && col <= width) {
col -= 1;
}
let currTile = document.getElementById(row.toString() + '-' + col.toString());
currTile.innerText = "";
} else if (e.code == "Enter") {
update();
}
if (!gameOver && row == height) {
gameOver = true;
document.getElementById("answer").innerText = word;
}
// Update the mode styles after processing input
applyMode();
}
function update() {
let guess = "";
document.getElementById("answer").innerText = "";
// String up the guesses into the word
for (let c = 0; c < width; c++) {
let currTile = document.getElementById(row.toString() + '-' + c.toString());
let letter = currTile.innerText;
guess += letter;
}
guess = guess.toLowerCase();
if (!guessList.includes(guess)) {
document.getElementById("answer").innerText = "Not in word list";
return;
}
let correct = 0;
let letterCount = {};
for (let i = 0; i < word.length; i++) {
let letter = word[i];
if (letterCount[letter]) {
letterCount[letter] += 1;
} else {
letterCount[letter] = 1;
}
}
for (let c = 0; c < width; c++) {
let currTile = document.getElementById(row.toString() + '-' + c.toString());
let letter = currTile.innerText;
if (word[c] == letter) {
currTile.classList.add("correct");
let keyTile = document.getElementById("Key" + letter);
keyTile.classList.remove("present");
keyTile.classList.add("correct");
correct += 1;
letterCount[letter] -= 1;
}
if (correct == width) {
gameOver = true;
}
}
for (let c = 0; c < width; c++) {
let currTile = document.getElementById(row.toString() + '-' + c.toString());
let letter = currTile.innerText;
if (!currTile.classList.contains("correct")) {
if (word.includes(letter) && letterCount[letter] > 0) {
currTile.classList.add("present");
let keyTile = document.getElementById("Key" + letter);
if (!keyTile.classList.contains("correct")) {
keyTile.classList.add("present");
}
letterCount[letter] -= 1;
} else {
currTile.classList.add("absent");
let keyTile = document.getElementById("Key" + letter);
keyTile.classList.add("absent");
}
}
}
row += 1;
col = 0;
// updating style
applyMode();
}
function applyFlip() {
var tiles = document.getElementsByClassName("inner");
var tilesArray = Array.from(tiles);
tilesArray.map(function (tile, i) {
tile.classList.add("flip");
tile.style.animationDelay = \
${i * 100}ms`;
});
}
var flipper = document.getElementById("flipper");
flipper.addEventListener("click", applyFlip);`
I am searching for the app that have a wide range of options to work with UML diagrams. Particularly, I am interested in displaying already existing UML file. If you know something cool I will be glad to hear it. And of course I already checked on the web what available now but they does not seem to have what I am searching for.
i just want to learn how to code. mostly want to freelance in web3 space. i work at a tech site but not as a dev lol. i also have close friends in cs. Most young devs i talk to say network is more important. deos a degree matter when it comes to landing jobs?
I’ve recently started a new job at a very well know energy company in the US and one of the programs we currently use works but could be so much more powerful and better. I’ve kind of been inspired to make a better version of the program as a new business venture but due to the complexity of the my job Im really stumped on the platform I should use. (I’m not a front/backend developer just FYI, just a guy with some python background that hates this program with a passion I’m stuck using. )
I thought about Electron or Python desktop application platforms but It’s a weird kind of environment I’m developing for. It needs to be able to take inputs from SCADA systems, be able to do calculations on its own based on data entries in to a spreadsheet style system. Takes integration with web based clients that our other systems use. So on one hand python seems the obvious pick and then on the other Electron makes sense. Not my industry but I’m gonna develop a replacement for this system if it kills me.
What do you guys think?
(This will be a data entry/log sheet/tracking system used for product deliveries in the pipeline industry)
I am front end developer but I have a little knowledge about UI design. Tried to look for tutorials but they all teach how to use a tool to create design and animations . Not how to know what is a good and friendly UI and whats not .
Been working on a little project, basic dns trafic scanner for potentional threats, but there are just so many things i can't even begin to breakdown, i'm currently reading docs on interracting with OS on lower level and looking at ways to actually implement it using c++, breaking it down into smaller chunks doesn't help because there are just too many things. Anyways, just want some general advice and nudge into the right direction, i did read faq before posting, but didn't find anything particularly useful apart from reading docs
EDIT: I want to eavesdrop on dns requests and responses in regards to other processes
I am just approaching the HTML + CSS world and I would like to create a menu-categories with cards.
Result I want: https://i.imgur.com/eCsDzYj.png
Each row must have 2 cards (of course it changes for mobile, but that's something i'll deal with later).Except for responsive (I will deal with this later, focusing on desktop now), I would like them to ALWAYS remain 2 cards per row regardless of how big the resolution of the page can be for someone.
From what I understand, this is possible to be done both with grid and flex, but I don't get the difference between the two approach and neither how (I mean, I get it partially)I searched Codepen to view some project to find the solution to "what should I use?" but even there I see many different approach and I don't know which one should be used.
What is the best approach in this case, and why?
m 1st semester student of csit. I have 6 hr of classes. Extra 2hr of travelling back and forth. So basically 8 hrs on college. I am physically burnt out after arriving home on 5 pm. I have assignments and some topics I need to study as I wasn't CS student in +2 and need to keep up. I only have about 3 hr of time after dinner. In that 3 hrs I have to do some assignment and practical and whatnot. So how can I manage to do programming and have a good grade?
I want to know what data streams are at its low level instead of just the definition "stream of data". Like how it is handeled, where it is mostly used etc.
I was learning Go and I came across the http module. There we have to close the Response body which must be closed which I was confused about. When I used chatgpt it responded that Response body is a stream and it needs to be closed to save system resources. When I requested for an example of streams in Python gave example through generators. So are streams really processed like generators?
I think that's not the case since streams are used in networking a lot and things like generators might not be used here. So how exactly stream is processed? If stream data is not stored anywhere (as GPT said) then why we need to close it ? Please provide a deep technical explanation else my brain won't be satisfied. (We don't do abstraction here lol)
What are the approaches and resources for TDD with Python?
maths or my brain doesnt workin unity using C# i have
Debug.Log("idz");
Debug.Log(distance_to_target());
Debug.Log(" is not less than ");
Debug.Log(min_dist_to_waypoint);
if (distance_to_target() < min_dist_to_waypoint)
{ Debug.Log("idz 2 ");
the output i get
idz 18.44753 is not less than0.1
why is that not true? why does "idz 2" never printim not crazy, i know that
18.44753 < 0.1
is true
public float min_dist_to_waypoint = 0.1f;
float distance_to_target()
{
float distsq = Mathf.Pow(transform.position.x - target_t.x, 2) + Mathf.Pow(transform.position.z - target_t.z, 2);
float dist = Mathf.Pow(distsq, 0.5f);
return dist;
}
when i add
Debug.Log("Distance type: " + distance_to_target().GetType().ToString());
Debug.Log("Min distance type: " + min_dist_to_waypoint.GetType().ToString());
i get
Min distance type: System.Single
Min distance type: System.Single
Hey all,
For context, I have a B.A. in History and have been working in Technical SEO for two years for a large automotive e-commerce agency. Took Front-End Dev cross-training and work with Wordpress, FTP, and Apache server redirects daily. I started exploring programming last summer and took all the free language courses from CodeAcademy HTML, CSS, Javascript, Python, PHP, and then took the Complete Web Dev course from Zero To Mastery. I know that Web Development is my thing and I enjoy learning new things/building every day, but feel like I need a boot camp or program to get me ramped up to be job-ready/build a portfolio.
Everything I am reading on Reddit is telling me that Bootcamps are scammy now, inflating numbers, the market is saturated and that it is not the time to commit 10k into this career transition. Given my background and the current market, should I sit tight and build things on my own or go to a bootcamp regardless of the current market conditions?
Any advice is appreciated, TYA
Im looking for an online tutor. I'm quite new to c# and struggling to complete a piece of coursework we've been assigned
I've always worked front end, but with my current job I am now on a programming team of two. The senior engineer has been hard to learn from and has been pretty uninvolved in teaching, or not really being clear. It doesn't help that they're also remote while I work in the office.
My main thing is I've always started working in projects that were already made. I wouldn't know how to build a full project from scratch and don't quite understand a lot of the back end basics.
Another big thing is I don't understand how the api connects to the database. I get it uses a query, and I understand SQL well enough, but as to how it actually connects via software and code I don't understand. There are multiple data sources within SQL Server Management Studio I can access.
Anyone else been a similar spot of not understanding these concepts? Can anyone recommend any tutorials or helpful videos. I've had trouble trying to figure this out because a lot of what I find seems to assume I already know a ton of beginning steps that I do not. Sorry if this is a bit vague and any advice is much appreciated thank you.
const theme = {
color: {
// or colors: {
fg: '#fff',
bg: '#111',
}
}
const icon = {
// or const icons = {
play: '\\f04b',
pause: '\\f04c',
};
What do you think?
const theme = {
color: {
// colors: {
fg,
bg: '#111',
}
}
const icon = {
// const icon = {
play: '\\f04b',
pause: '\\f04c',
};
What do you think?
Hello, I’m trying to make a python program that everytime that a specific account posts a tweet it grabs it, translates it and gets published on another account already translated (it must include any url or/and image that’s attached to the post), I don’t know if it’s possible to do with the free twitter API or if there is another method. Can someone explain me how to do it? Thanks
I, along with three other students, am working on a C# tab in Microsoft Teams. All of us, except for one, are getting the error message "Failed to get access token from OAuth identity server, please login(consent) first" when attempting to use the Graph API.
At first, everything worked just fine, but then, one by one, each team member started getting this error. The only one who did not (yet) get this error is the person who initially created the project. All team members are using the same versions of dependencies and the same version of the program. We also all have identical settings.
But the weirdest thing is that we did not have that error in the beginning so we have no idea what might be wrong. We've checked the settings on Azure and found nothing unusual.
None of us have worked with Microsoft Teams apps or the Graph API before, so we have no idea why we keep getting this error. We tried googling but that didn't help much. Any idea what might be wrong? Is there a way to bypass this?
Edit: forgot to mention that I can call the Graph API when I run the tab locally, but when I click on the tab in the Microsoft Teams application it doesn't work.
Hello,
I’m wondering if anyone has thoughts or pointers on how to gather qualitative metrics like the kind given by the time command with a bash script. Currently the time metrics and the number of lines is about all I can think of. Would love some more data to fill out a report I’m doing.
It is well-known that by interchanging the nested for loop orders in a matrix multiplication, we can speed up the code. The faster code below exploits cache locality.
Slow code:
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
C[i][j] += A[i][k] * B[k][j];
}
}
}
Fast code: (note the change of i,j,k loop order)
for (int i = 0; i < n; i++) {
for (int k = 0; k < n; k++) {
for (int j = 0; j < n; j++) {
C[i][j] += A[i][k] * B[k][j];
}
}
}
My question is, since this is such a well-known optimization, why don't compiler just optimize it for you?
Hi.
I've been programming for around 5 years, I've always been a game developer, or at least for the first 3 years of my programming journey. 2 years ago I decided it was "enough" with game development and started learning Python, which to this days, I still use very frequently and for most of my projects.
December started 12 days ago, and for my first year I decided to try the Advent of Code 2023, which is basically 1 programming problem everyday and they get harder and harder each day. I started HARD, I ate problems, day by day, until... day 10; things started getting pretty hard and couldn't do - I think - pretty average difficulty problems.
Then I started wandering... am I a bad programmer? I mean, some facts tell me I'm not, I got a pretty averagely "famous" (for the GitHub standards) on my profile and I'm currently writing a transpiled language. But why?... Why can't I solve such simple projects? People eat problems up until day 25, and I couldn't even get half way there, and yeah "comparison is the thief of joy" you might say, but I think I'm pretty below average for how much time I've been developing games and stuff.
What do you think tho? Do I only have low self esteem?
I started learning programming thanks to CS50. I feel I've learned a decent amount of things as I completed CS50x, CS50p, and I'm almost done with CS50w.
For my final project, I decided to build an app that works on mobile as well as on the web. So, I started reading about Flutter. I watched a few tutorials on Dart and Flutter. So far, it feels like it's something akin to writing HTML+CSS+JS on one page. It's a little complicated, but not too difficult.
The thing is, I decided to learn programming to change my career, and I wouldn't like to waste my time on something that has no market value. Is this a good stack to master in order to get a decent job, or should I focus my time on something else?
If you'd like to know what other skills I have to provide me with some advice, I speak English and Spanish, and I'm learning Italian as well. I'm currently learning more about Git while completing CS50w.
I'm not much of a developer, I've actually been a sysadmin for most of my career. So I'm not even sure I'll have the right terminology. I'm just trying to help my team, and I don't know exactly how to communicate with them.
We have an application that we need to encrypt the contents of a couples files, one being a connection string, and they vary across the environments. When we build a release, we build it for that specific environment.
So my thought was to store the relevant connection string on our cloud secrets storage and making calls to that and retrieve it per environment, that way we don't have a separate build for DEV/TEST/PROD, we just have one.
My hope I suppose is when the app is called, it will access the secret and fill in the correct string based on the environment it's installed in. If the secret key value pair named is always stored as "connection-string", and the value is set per environment, the correct connection-string will be applied, correct?
But I'll be honest, I have no idea if this is possible, or good practice, or if I'm leading my team in the right direction. If I install the msi, will it do what I stated? Or would it fail miserably the moment it leaves DEV?
Should I be looking at a different approach?
For those not familiar with the paper, it's here: https://en.wikisource.org/wiki/Lambda:_The_Ultimate_GOTO
The paper demonstrates a strategy for optimizing the implementation of procedure calls that essentially gives you tail call elimination "for free", and will also eliminate some "needless" book-keeping for frame setup.
Central to the strategy is the idea that the caller should be responsible for setting up the callee's frame.
When I look at the output of modern compilers, I seem to always see that the callee still manage its own frame, and when tail call elimination happens, it is usually treated as a special case (or so it seems to me).
I'm wondering why modern compilers don't seem to adopt the approach Steele suggests. Does modern hardware make it obsolete? --I know machines today can do some reordering of instructions and often execute multiple instructions in parallel on a single core. Or was this it just a bad idea to begin with?
I haven't been able to find any critiques of this paper, and I'm just curious why I can't find any compilers that implement procedure calls the way Steele suggests.
I have done CS50X and CS50P.
I know I can code and want to do mobile app development, I have followed his roadmap and done the basics of Kotlin, and now I am at Android Fundamentals for Beginners. I am confused because it is complicated and seems like a whole lot of memorization of x y z steps and words which I forget in a few videos.
His videos are a bit outdated so if an issue arises I have to search it online so I am constantly bombarded with buzzwords like activity, fragments, etc which I don't know.
I can't seem to be able to do much except just copy-pasting what is shown (if it works) and it doesn't feel like I am learning a lot.
Please help me.
I am trying to learn how to create chrome extensions. Creating a simple extension which console logs the title of the current youtube video
This is the HTML for the Youtube Title<div id="title" class="style-scope ytd-watch-metadata">
<ytd-badge-supported-renderer class="style-scope ytd-watch-metadata" disable-upgrade="" hidden="">
</ytd-badge-supported-renderer>
<h1 class="style-scope ytd-watch-metadata">
<yt-formatted-string force-default-style="" class="style-scope ytd-watch-metadata">Elon’s "based" Grok AI has entered the chat…</yt-formatted-string>
</h1>
<ytd-badge-supported-renderer class="style-scope ytd-watch-metadata" disable-upgrade="" hidden="">
</ytd-badge-supported-renderer>
</div>
This is the code I have written to fetch the title. This code is in the ContentScript.(()=>{
console.log(document.getElementById("title"));
console.log(document.querySelector("#title > h1 > yt-formatted-string"));
})();
The first line gives the output<div id="title" class="style-scope ytd-watch-metadata">
But the second line outputsnull
I have checked and the second line gives the correct output when typed in the chrome console. It doesn't work when I'm trying to do it using javascript.
Here is my manifest.json{
"manifest_version": 3,
"name": "FillModule",
"description": "Fill test 001",
"version": "1.0.0",
"permissions": ["storage", "tabs"],
"author":"Aniket Vishwakarma",
"action": {
"default_icon": "assets/doggy.png",
"default_title": "Fill",
"default_popup": "popup/popup.html"
},
"background" : {
"service_worker": "background/background.js"
},
"content_scripts": [
{
"matches": ["https://*.youtube.com/*"],
"js": ["content/content.js"]
}
]
}
MY ATTEMPTS
I have tried to wrap it in a "DOMContentLoaded" like sodocument.addEventListener("DOMContentLoaded", () => {
console.log(document.querySelector("#title > h1 > yt-formatted-string"));
console.log(document.getElementById("title"));
});
But then none of the lines execute.
I found a solution on StackOverflow for why the "DOMContentLoaded" was not working. That solution went like thisif (document.readyState !== 'loading') init();
else document.addEventListener('DOMContentLoaded', init);
function init() {
console.log(document.getElementById("title"));
console.log(document.querySelector("#title > h1 > yt-formatted-string"));
}
But then I get the same result<div id="title" class="style-scope ytd-watch-metadata">
null
Can someone explain what's happening here and how to fix this ?
Hello! Not sure if this is the best place to post this, but r/programming says it's "Not a support forum" so here I am.
I'm currently working on a project to streamline the installation and setup of Matrix Synapse onto Raspberry Pis from a Matrix machine. Currently I've got everything set up and working using an Ansible playbook which I can run through WSL on my Windows machine. The issue is, I'm trying to make a setup wizard which I can share and run on Windows and just assumed I could run Ansible with Python for this purpose, but I didn't take into account that Ansible doesn't work on Windows without WSL 😅.
So my main question is, does anyone know of any Windows friendly alternatives to something like Ansible, for setting up a Raspberry Pi? Or would the easiest thing just to write a Python program that can SSH into the Pi and do things manually? The ultimate goal is the create a one stop shop to transform a fresh Pi into a Matrix Server.
Hello everybody! This time I will try to describe the principles of encapsulation and inheritance.
Encapsulation
Last time I stopped at the Text class. I'm going to make changes to it now and maybe it will get better. You can copy the code to the sandbox and try to execute it.
<?php
class Text {
private $text;
public function __construct($text){
$this->text = $text;
}
public function printText() {
return $this->text;
}
}
$hello = new Text("Hello, "); // create object hello
$world = new Text("World!"); // create object world
echo $hello->printText(); // call hello object print method
echo $world->printText(); // call world object print method
echo PHP_EOL.get_class($hello); // check class name
echo PHP_EOL.get_class($world); // check class name
?>
Here I have added a class constructor. I use it to pass a parameter with text. This parameter is written to the text property. I use the private keyword declaring the text property, which prohibits access to the property from outside the class. The get_class function returns the class name. Here I will check that the class of the two objects is the same, why is this important? We will find out in the following posts.
Defining the ability to access class properties and methods (public, private, protected) is Visibility or Access Modifiers.
So it turned out that the Text class works with the parameter that I passed through the constructor and the methods that I described in the class. This combination of data and methods of working with them + Visibility is Encapsulation.
Inheritance
So, we have a class that takes a parameter and prints the text. In our project, you need to print text in two styles. Headings that will be written in caps and regular lines that will have only the first letter large. We can write functions for each case. We can write different classes. Or we can use the Text class and expand its capabilities. I'll write a couple more classes.
<?php
class Text {
protected $text;
public function __construct($text){
$this->text = $text;
}
public function printText() {
return $this->text;
}
}
class Header extends Text {
public function printText() {
return strtoupper($this->text);
}
}
class Sentence extends Text {
public function printText() {
return ucfirst(strtolower($this->text));
}
}
$header = new Header("hello, world!");
$sentence = new Sentence("hello, WORLD!");
echo $header->printText();echo PHP_EOL;
echo $sentence->printText();
?>
Now I have a class that outputs the text unchanged and two classes that output the text in the desired way. At the same time, child classes use part of the superclass code, which is good. No one likes to repeat the code.
Conclusion
Encapsulation, access modifiers, and inheritance are already very different from using simple functions. Extending the capabilities of classes is much better than rewriting individual functions or methods of superclasses. Therefore, it is good to use them.
Please write in the comments which of the following topics you want the next article to be devoted to.
Thanks a lot for your attention, replies and comments. See you in the next article.