• Breaking News

    Friday, July 2, 2021

    What's up with the "Here is a terribly written piece of code, can you tell us what it will print?" in programming tests? learn programming

    What's up with the "Here is a terribly written piece of code, can you tell us what it will print?" in programming tests? learn programming


    What's up with the "Here is a terribly written piece of code, can you tell us what it will print?" in programming tests?

    Posted: 02 Jul 2021 06:05 AM PDT

    When I was at the university, and took my final exam in some courses they LOVED these sorts of questions so much that 20~40% of the score was based off these questions.

    Now that I sign up to LinkedIn to look for a job, they also ask me the same questions.

    Some of them may be relevant like knowing 0, null = to false, or different between == and === and scoping.

    But I came across this question:

    var a = 5; console.log(a++) console.log(++a) 

    Why the hell would I log (a = a+1) in first place?

    And this is just one of many examples to callback hell, bad programming, and irrelevant questions that I need to decipher. I program for 3 years, created many projects and written shit load of code by this point, and all that I can think of when reading these questions is "you should fire the guy who wrote this code instead of asking me what it will print".

    I don't think they actually show anything about knowledge in a programming language, so why they keep asking those?

    EDIT:

    I feel like many people missed the point I tried to make, and also some focused and didn't understand WHY the above example is an example to terrible code, so I will explain that.

    A rule about writing a function is that the function SHOULD NOT CHANGE THE ORIGINAL VALUE OF THE ATTRIBUTE, BUT RETURN THE DESIRED VALUE.

    Example:

    // good: function addOne(num) { return num + 1; } // Bad function addOne(num) { num++; } 

    The point of console.log() is to print the value, you should NEVER change the value of an attribute from that method.

    What it logs isn't relevant, because it's not a real use case in first place.

    Edit 2:

    I admit I came out an ass in this post, mostly because the terrible example that I've shown and apparently didn't fully understand.

    While this specific code is indeed a bad code (see Edit 1), I now understand its purpose for the example, while I think this example could be written using better code, and that putting it inside console.log change the context. I admit that in fact didn't know about the difference between a++ and ++a as I thought - And therefor came out an ass.

    submitted by /u/xSypRo
    [link] [comments]

    What do you wish you knew at the beginning of your programming journey?

    Posted: 01 Jul 2021 05:44 AM PDT

    What are some advices derived from your experience which you could give to a programming newbie?

    submitted by /u/mrko900
    [link] [comments]

    how often is swift language used?

    Posted: 02 Jul 2021 12:40 PM PDT

    as mentioned in the title, how often is swift used and why have I barely heard about it? I am new to programming and i've heard about java, js, html, css, c#, python, SQL,

    but I've never heard about swift until my upcoming camp mentioned that we would be learning it!

    also, what type of things is swift used for? and how is it correlated to Apple?

    submitted by /u/Elegant-Permission87
    [link] [comments]

    "Automate the Boring Stuff with Python" online course is free to sign up for the next few days with code JUL2021FREE

    Posted: 01 Jul 2021 09:55 AM PDT

    https://inventwithpython.com/automateudemy (This link will automatically redirect you to the latest discount code.)

    You can also click this link or manually enter the code: JUL2021FREE

    https://www.udemy.com/course/automate/?couponCode=JUL2021FREE

    This promo code works until the 4th (I can't extend it past that). Sometimes it takes an hour or so for the code to become active just after I create it, so if it doesn't work, go ahead and try again a while later. I'll change it to JUL2021FREE2 in three days.

    Udemy has changed their coupon policies, and I'm now only allowed to make 3 coupon codes each month with several restrictions. Hence why each code only lasts 3 days. I won't be able to make codes after this period, but I will be making free codes next month. Meanwhile, the first 15 of the course's 50 videos are free on YouTube.

    Side note: My latest book, The Big Book of Small Python Projects, is out. It's a collection of short but complete games, animations, simulations, and other programming projects. They're more than code snippets, but also simple enough for beginners/intermediates to read the source code of to figure out how they work. The book is released under a Creative Commons license, so it's free to read online. (I'll be uploading it this week when I get the time.) The projects come from this git repo.

    Frequently Asked Questions: (read this before posting questions)

    • This course is for beginners and assumes no previous programming experience, but the second half is useful for experienced programmers who want to learn about various third-party Python modules.
    • If you don't have time to take the course now, that's fine. Signing up gives you lifetime access so you can work on it at your own pace.
    • This Udemy course covers roughly the same content as the 1st edition book (the book has a little bit more, but all the basics are covered in the online course), which you can read for free online at https://inventwithpython.com
    • The 2nd edition of Automate the Boring Stuff with Python is free online: https://automatetheboringstuff.com/2e/
    • I do plan on updating the Udemy course for the second edition, but it'll take a while because I have other book projects I'm working on. If you sign up for this Udemy course, you'll get the updated content automatically once I finish it. It won't be a separate course.
    • It's totally fine to start on the first edition and then read the second edition later. I'll be writing a blog post to guide first edition readers to the parts of the second edition they should read.
    • I wrote a blog post to cover what's new in the second edition
    • You're not too old to learn to code. You don't need to be "good at math" to be good at coding.
    • Signing up is the first step. Actually finishing the course is the next. :) There are several ways to get/stay motivated. I suggest getting a "gym buddy" to learn with. Check out /r/ProgrammingBuddies
    submitted by /u/AlSweigart
    [link] [comments]

    Creating a finance manager as a personal project

    Posted: 02 Jul 2021 12:59 PM PDT

    I'm pretty new to programming, and I wanted to tackle a project to learn more tech and just improve my coding skills in general. So far, I only have experience in python, java, and some of their libraries. So, I was thinking of making a personal finance/expense manager using javascript to learn more.

    The tech I was thinking of using were: plaid api to get financial data, and node.js for data visualization making the application functional. I'm not sure if this is the right tech stack I should be using, so if anyone has any information about other financial data apis or frameworks I should use instead, that would be great!

    This where I'm a little stuck– I've only ever had experience with web applications, not mobile apps, and I was wondering how easy it is to convert a javascript web app to, let's say, an iphone app? Additionally, I have little to no experience in javascript, and was wondering if anyone has any resources to help me along they way of creating this app? Last thing– how should I go about integrating user authentication? Thanks!

    submitted by /u/mr-bacteria
    [link] [comments]

    How do computers run multiple programs

    Posted: 02 Jul 2021 04:00 AM PDT

    If I'm correct, I think that computers can only read code line by line.

    If this is the case, how can a computer run multiple programs at the same time, and on top of that how does Windows 10, software written in C, run programs written in Python, JavaScript, and any other language?

    submitted by /u/YianniBOMB
    [link] [comments]

    Should I start applying for jobs or keep learning more?

    Posted: 02 Jul 2021 11:04 AM PDT

    I've been learning programming for about 4 months full time now, started with CS50 and now nearing the react part in TOP, although I'm considering switching to Helsinki's FSO to learn react. My question is, should I apply for a junior dev job now with my current vanilla JS knowledge or learn React and and then apply for a better job? I'm still in the process of building my [portfolio ](angiee39.github.io),

    submitted by /u/rippedtech
    [link] [comments]

    WHAT MOTIVATES YOU AS A PROGRAMMER

    Posted: 02 Jul 2021 01:36 AM PDT

    I've been on programming for almost two years now. Started with python(just to help me understand programming) and eventually moved to c++. (I don't have a computer and can't afford one, so I use a debian OS I installed in termux on my phone). I started taking frontend development seriously in February but all of a sudden I just can't find any motivation to code anymore and loosing interest gradually. But I want to be good at frontend development together with software development in the near future. So my question is what keeps you going as a programmer?

    submitted by /u/xirlohm
    [link] [comments]

    How would you design a system that adds metrics to preexisting data?

    Posted: 02 Jul 2021 12:45 PM PDT

    So say I had multiple services that I can retrieve data from. This data can be anything from user profiles to comments for a video. I want to add related metrics like ratings, or labels.

    Should I just add an extra field to the data to hold the metric?

    What I'm currently thinking of is this:

    Have a separate service just for adding this extra field: Use a key value pair which the data is hashed to a key, and the value is the metric and info on how to retrieve the data

    It's easy to insert/write. But if you want to get lots of metrics for multiple objects (read) you could have a separate database thats like a cache to store both the retrieved data and the metrics together.

    Does this make sense?

    submitted by /u/granite_towel
    [link] [comments]

    My problem with learning programming.

    Posted: 01 Jul 2021 12:15 PM PDT

    I tried to learn programming on freecodecamp. I went through the HTML course but when I finished I realized something: I didn't remember how to do anything! Do you know what I mean?

    Am I supposed to remember every line of code? If not, how could I program anything without plagiarizing?

    submitted by /u/bilad-al-ubat
    [link] [comments]

    Is wanting to make a chat app too much for a near beginner?

    Posted: 02 Jul 2021 03:30 PM PDT

    I've been in college for programming for a year, I haven't done much aside from some basic C# and Python a year back and this year I had to deal with C# and HTML.

    I really want to make a chat app as a like future endeavor, is that too steep of an expectation for me?

    submitted by /u/DaylitSoul
    [link] [comments]

    Programming Boot Camps

    Posted: 02 Jul 2021 03:24 PM PDT

    Hello there, I am a college student whos major is CS, in going into my second year and its just been the general studies so far, I'm interested in learning the basics of coding and programming before I actually take courses for it and was wondering if they are any boot camps you guys highly recommend free or paid that would help me learn the basics and more and possibly land a part time job in the programming field while I go through school or at least make my CS classes when i do take them slightly easier

    submitted by /u/YuriHaThicc
    [link] [comments]

    Junior Dev who isn't feeling "good enough" for the work/company

    Posted: 02 Jul 2021 03:20 PM PDT

    Hey guys,

    I joined a startup about a month-ish ago after I graduated as a junior developer. They work on some really cool stuff. They also hired about 4 other junior devs alongside me. In comparison I feel like the weakest of the bunch, they at least specialize in something but myself I like a little bit of everything. They got put into tasks regarding their likes while I got stuck on some very meaningless things. I feel so inadequate for the position it's not funny, I get stressed out about every task I have. The boss has told me that he's happy with me, likes me etc. but I don't feel like I deserve that and they are just saying it to be nice. I haven't had "imposter syndrome" to this extent before, because of being put on meaningless tasks etc. Is this normal?

    submitted by /u/National_Potato
    [link] [comments]

    How to motivate myself to learn?

    Posted: 02 Jul 2021 03:11 PM PDT

    I'm a student and I have a strong desire to pursue my goals and to learn to program properly. I have some knowledge of C# but I want to become more focused on web development. I bought a really good course that covers HTML, CSS, and JS but I can never find the time or motivation to sit down and learn. I always get sidetracked, looking at my phone, or opening a new tab and looking at pointless shit on the internet. Then once I stop, I end up not looking at the course for at least a week, usually. How do I learn it and motivate myself? Tips appreciated.

    TLDR: Student learning web development but can not motivate themself to actually sit down and learn.

    submitted by /u/BlackWogPki
    [link] [comments]

    Alternative for Algolio for search

    Posted: 02 Jul 2021 03:06 PM PDT

    Hey Guys,

    Algolia is recently asking for putting their logo next to the search bar in your website if you are using their free service, which is non-sense. I wonder if there is another alternative for search that is free and also works with GraphCMS?

    Best

    submitted by /u/hassanzadeh
    [link] [comments]

    Automate the Boring Stuff with Python Programming

    Posted: 02 Jul 2021 03:06 PM PDT

    If you're an office worker, student, administrator, or just want to become more productive with your computer, programming will allow you to write code that can automate tedious tasks. This course follows the popular (and free!) book, Automate the Boring Stuff with Python.

    Automate the Boring Stuff with Python was written for people who want to get up to speed writing small programs that do practical tasks as soon as possible. You don't need to know sorting algorithms or object-oriented programming, so this course skips all the computer science and concentrates on writing code that gets stuff done.

    This course is for complete beginners and covers the popular Python programming language. You'll learn basic concepts as well as:

    • Web scraping
    • Parsing PDFs and Excel spreadsheets
    • Automating the keyboard and mouse
    • Sending emails and texts
    • And several other practical topics

    By the end of this course, you'll be able to write code that not only dramatically increases your productivity, but also be able to list this fun and creative skill on your resume.

    Free to join: https://www.udemy.com/course/automate/?couponCode=JUL2021FREE

    submitted by /u/onlinecoursesfree
    [link] [comments]

    Import confusion

    Posted: 02 Jul 2021 11:02 AM PDT

    I have the following directory tree:

    Programming Projects DeucesPackage Deuces deck.py PokerCounter PokerCounter.py 

    The DeucesPackage and Deuces folders both contain an __init__.py file. The deck.py file contains a class named Deck.

    I want to use the Deck class in PokerCounter.py. I keep getting the dreaded "attempted relative package with no known parent package" error. At one point, PyCharm let me use

    from ..DeucesPackage import deuces.deck 

    but I got the error when I tried to run the program. Now PyCharm won't accept that line or any variant of it.

    How am I supposed to import the Deck class into my program?

    submitted by /u/CedricCicada
    [link] [comments]

    Best c++ courses/resources to learn c++

    Posted: 02 Jul 2021 07:07 AM PDT

    Hello, as the holidays have just started i'd like to take my time and learn c++ to an advanced level(if possible, and also i am pretty much a beginner( i only know the basics such as arrays, loops)). With that, i got one question: what are the best resources or courses (paid or free) that i could use to learn it.

    I wanted to use sololearn but after some research i decided to use something else(as i read that sololearn isnt that good of a source)

    Anyway, thanks for answers!

    submitted by /u/Buglante
    [link] [comments]

    How to connect LCD display to keypad?

    Posted: 02 Jul 2021 08:02 AM PDT

    Hi, I want to program my keypad to be able to write on the LCD display when the numbers are pressed. I am using python on the raspberry pi 4. The idea of my program is to make a timer which shows you the time and of course has the ability to be a timer. Here's the code so far.

    from PCF8574 import PCF8574_GPIO

    from Adafruit_LCD1602 import Adafruit_CharLCD

    from time import sleep, strftime

    from datetime import datetime

    import RPi.GPIO as GPIO

    import Keypad

    ROWS = 4

    COLS = 4 #number of columns and rows of the Keypad

    keys = [ '1','2','3','A', #key code

    '4','5','6','B',

    '7','8','9','C',

    '*','0','#','D' ]

    rowsPins = [12,16,18,22] #connect to the row pinouts of the keypad

    colsPins = [19,15,13,11] #connect to the column pinouts of the keypad

    def get_time_now(): # get system time

    return datetime.now().strftime(' %H:%M:%S')

    def loop():

    mcp.output(3,1) # turn on LCD backlight

    lcd.begin(16,2) # set number of LCD lines and columns

    while(True):

    #lcd.clear()

    lcd.setCursor(0,0)

    lcd.message("Timer: " + "\n")

    lcd.message( get_time_now() )

    sleep(1)

    def destroy():

    lcd.clear()

    PCF8574_address = 0x27 # I2C address of the PCF8574 chip.

    PCF8574A_address = 0x3F # I2C address of the PCF8574A chip.

    # Create PCF8574 GPIO adapter.

    try:

    mcp = PCF8574_GPIO(PCF8574_address)

    except:

    try:

    mcp = PCF8574_GPIO(PCF8574A_address)

    except:

    print ('I2C Address Error !')

    exit(1)

    # Create LCD, passing in MCP GPIO adapter.

    lcd = Adafruit_CharLCD(pin_rs=0, pin_e=2, pins_db=[4,5,6,7], GPIO=mcp)

    if __name__ == '__main__':

    print ('Program is starting ... ')

    try:

    loop()

    except KeyboardInterrupt:

    destroy()

    def loop():

    keypad = Keypad.Keypad(keys,rowsPins,colsPins,ROWS,COLS) #creat Keypad object

    keypad.setDebounceTime(50) #set the debounce time

    while(True):

    key = keypad.getKey()

    if(key != keypad.NULL):

    print ("You Pressed Key : %c "%(key))

    if __name__ == '__main__':

    print ("Program is starting ... ")

    try:

    loop()

    except KeyboardInterrupt:

    GPIO.cleanup()

    submitted by /u/Wholesome_Boye
    [link] [comments]

    What do you guys think performance wise, of always updating/rendering the ui when someone interacts with a component?

    Posted: 02 Jul 2021 01:44 PM PDT

    So I have this crowd fund project thing, and every time someone adds an amount of money to a project, the ui updates with a new state, thus rendering a new contribution amount in the ui instantaneously. But I was just wondering if I should instead of having it update every time someone adds money, let it update when they start the app up again, or switch to the screen. I was just wondering, would the performance be bogged down if thousands of users were adding money (and thus, rendering a new updated number each time).

    submitted by /u/ThisSoFrustrating
    [link] [comments]

    I need help with shooting in Pygame

    Posted: 02 Jul 2021 01:42 PM PDT

    Hi, I trying to make my player shoot projectails but I still don't really know how to do it, tried to do it but it's not working as I thought, can someone help me with it?

    Here's my code:

    import pygame import random from pygame.locals import * vec = pygame.math.Vector2 screen_width = 600 screen_height = 900 class Player(pygame.sprite.Sprite): def __init__(self): super(Player, self).__init__() self.surf = pygame.Surface((25, 25)) self.surf.fill((0, 255, 0)) self.rect = self.surf.get_rect() self.rect.center = (screen_width/2 , screen_height/2) self.position = vec(screen_width /2, screen_height/2) def update(self, pressed_keys): # Player input if pressed_keys[K_UP]: self.rect.move_ip(0,-1) if pressed_keys[K_DOWN]: self.rect.move_ip(0, 1) if pressed_keys[K_LEFT]: self.rect.move_ip(-1, 0) if pressed_keys[K_RIGHT]: self.rect.move_ip(1, 0) #Player movement if self.rect.left < 0: self.rect.left = 0 if self.rect.right > screen_width: self.rect.right = screen_width if self.rect.top <= 0: self.rect.top = 0 if self.rect.bottom >= screen_height: self.rect.bottom = screen_height self.rect.center = pygame.mouse.get_pos() def create_bullet(self): return Bullet(pygame.mouse.get_pos()) # Shooting class Bullet(pygame.sprite.Sprite): def __init__(self): super(Bullet, self).__init__() self.surf = pygame.Surface((25, 15)) self.surf.fill((0, 0, 0)) self.rect = self.surf.get_rect() self.position = vec(screen_width /2, screen_height/2) def update(self): self.rect.speed += 2 class Enemy(pygame.sprite.Sprite): def __init__(self): super(Enemy, self).__init__() self.surf = pygame.Surface((25, 25)) self.surf.fill((255, 0, 0)) self.rect = self.surf.get_rect() speed = 1 self.velocity = random.choice(((speed, 0), (-speed, 0))) def update(self): self.rect.move_ip(self.velocity) if self.rect.right < 0: self.kill() if self.rect.left > screen_width: self.kill() # enemies spawn on the edges of the window if self.rect.left <= 0: self.rect.left = random.randint(screen_width-50,screen_width+100) if self.rect.right >= screen_width: self.rect.right < random.randint(screen_width+20,screen_width+100) if self.rect.top <= 0: self.rect.top = random.randint(0,screen_height) if self.rect.bottom <= screen_height: self.rect.bottom < random.randint(0,screen_height) pygame.init() screen = pygame.display.set_mode((screen_width, screen_height)) ADDENEMY = pygame.USEREVENT + 1 pygame.time.set_timer(ADDENEMY, 600) player = Player() bullet = pygame.sprite.Group() enemies = pygame.sprite.Group() all_sprites = pygame.sprite.Group() all_sprites.add(player, bullet) running = True fps_limit = 100 clock = pygame.time.Clock() clock.tick(fps_limit) while running: clock.tick(fps_limit) for event in pygame.event.get(): if event.type == KEYDOWN: if event.key == K_ESCAPE: running = False elif event.type == QUIT: running = False elif event.type == ADDENEMY: new_enemy = Enemy() enemies.add(new_enemy) all_sprites.add(new_enemy) elif event.type == pygame.MOUSEBUTTONDOWN: bullet.add(player.create_bullet()) pressed_keys = pygame.key.get_pressed() player.update(pressed_keys) enemies.update() screen.fill((0, 0, 0)) for entity in all_sprites: screen.blit(entity.surf, entity.rect) pygame.display.flip() if pygame.sprite.spritecollideany(player, enemies): player.kill() running = False 
    submitted by /u/Venomiks338
    [link] [comments]

    How to use chrome.runtime.sendMessage on a express.js server

    Posted: 02 Jul 2021 01:38 PM PDT

    I'm working on a chrome extension which I want to communicate back and forth with an express.js web sever. The documentation says

    From the web page, use the runtime.sendMessage or runtime.connect APIs to send a message to a specific app or extension. For example:

    // The ID of the extension we want to talk to. var editorExtensionId = "abcdefghijklmnoabcdefhijklmnoabc"; // Make a simple request: chrome.runtime.sendMessage(editorExtensionId, {openUrlInEditor: url}, function(response) { if (!response.success) handleError(url); }); 

    I just don't understand where exactly this piece of code would go. Do I need to write a separate service worker for the backend, or put this in the index file of the backend..?

    Thanks!

    submitted by /u/ChadLovesStacey
    [link] [comments]

    Where should I start to learn C#

    Posted: 02 Jul 2021 01:33 PM PDT

    Hello, I'm a hobbyist game dev but I only used Gamemaker Studio 2 before but now I want to change to Unity. I searched Unity a bit and learn't it uses C#. I don't know anything about C# and couldn't find somewhere to start learning. Can you guys recommend a place to start learning?

    submitted by /u/rlElectric
    [link] [comments]

    About GitHub CoPilot

    Posted: 02 Jul 2021 01:12 PM PDT

    Does it generate readable and maintainable code?

    submitted by /u/Javatype
    [link] [comments]

    I did it!

    Posted: 01 Jul 2021 01:04 PM PDT

    I'm super excited and still a bit in shock. I just accepted my first position as a full stack software engineer. Those of you who are current engineers what are some tips/ things you wish you knew when you started your first position?

    submitted by /u/luckyaces1313
    [link] [comments]

    No comments:

    Post a Comment