1. Java / Говнокод #27044

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    var io = java.io
    var BufferedReader = io.BufferedReader
    var BufferedWriter = io.BufferedWriter
    var InputStreamReader = io.InputStreamReader
    var OutputStreamWriter = io.OutputStreamWriter
    
    var Socket = java.net.Socket
    var socket = new Socket("localhost", 5050)
    var input = new BufferedReader(new InputStreamReader(socket.getInputStream()))
    var output = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
    
    while(true){
      var data = input.readLine()
      console.log(data)
    }

    Один петух написал мне в три часа ночи с прозьбой помочь с кодом

    digitalEugene, 21 Октября 2020

    Комментарии (85)
  2. Java / Говнокод #27041

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    final class Point {
        public final int x;
        public final int y;
    
        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
    
        // state-based implementations of equals, hashCode, toString
        // nothing else
    
    }

    is "just" the data (x, y). Its representation is (x, y), its construction protocol accepts an (x, y) pair and stores it directly into the representation,
    it provides unmediated access to that representation, and derives the core Object methods directly from that representation.
    And in the middle, there are grey areas where we're going to have to draw a line.

    Other OO languages have explored compact syntactic forms for modeling data-oriented classes: case classes in Scala, data classes in Kotlin, and record classes in C#.
    These have in common that some or all of the state of a class can be described directly in the class header -- though they vary in their semantics
    (such as constraints on the mutability or accessibility of fields, extensibility of the class, and other restrictions.)

    Committing in the class declaration to at least part of the relationship between state and interface enables suitable defaults to be derived for many common members.
    All of these mechanisms (let's call them "data classes") seek to bring us closer to the goal of being able to define Point as something like:

    record Point(int x, int y) { }

    [u]https://openjdk.java.net/jeps/359
    https://cr.openjdk.java.net/~briangoetz/amber/datum.html[u]

    3.14159265, 19 Октября 2020

    Комментарии (49)
  3. Java / Говнокод #27011

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    [code]
                lengthMapping.put("pt", Float.valueOf(1f));
                // Not sure about 1.3, determined by experiementation.
                lengthMapping.put("px", Float.valueOf(1.3f));
                lengthMapping.put("mm", Float.valueOf(2.83464f));
                lengthMapping.put("cm", Float.valueOf(28.3464f));
                lengthMapping.put("pc", Float.valueOf(12f));
                lengthMapping.put("in", Float.valueOf(72f));
    [/code]

    MAPTbIwKA, 08 Октября 2020

    Комментарии (103)
  4. Java / Говнокод #26991

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public static <T> Comparator<T> reverseOrder(Comparator<T> cmp) {
        if (cmp == null)
            return reverseOrder();
    
        if (cmp instanceof ReverseComparator2)
            return ((ReverseComparator2<T>)cmp).cmp;
    
        return new ReverseComparator2<>(cmp);
    }

    кишки стандартной библиотеки йажи продолжают радовать, хорошо хоть нет ReverseComparatorFinal или ReverseComparatorBassBoostedByKirillXXL

    Fike, 30 Сентября 2020

    Комментарии (8)
  5. Java / Говнокод #26976

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    /**
         * Change the zoom level to the specified value. Specify 0.0 to reset the
         * zoom level.
         *
         * @param zoomLevel The zoom level to be set.
         */
        public void setZoomLevel(double zoomLevel);

    Когда-то я думал, что zoom 100% это 1.0. И что на zoom нужно умножать. Но оказалось, что я анскильный.

    DypHuu_niBEHb, 24 Сентября 2020

    Комментарии (23)
  6. Java / Говнокод #26970

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    public void startLoginService(User paramUser) {
        if (paramUser != null) {
            Intent intent = new Intent((Context)this, LoginService.class);
            intent.putExtra("LOGIN_KEY", paramUser.getLogin());
            intent.putExtra("PASSWORD_KEY", String.valueOf(paramUser.getId()));
            startService(intent);
        }
    }

    GDMaster, 22 Сентября 2020

    Комментарии (37)
  7. Java / Говнокод #26969

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    public static UUID fromString(String name) {
            String[] components = name.split("-");
            if (components.length != 5)
                throw new IllegalArgumentException("Invalid UUID string: "+name);
            for (int i=0; i<5; i++)
                components[i] = "0x"+components[i];
    
            long mostSigBits = Long.decode(components[0]).longValue();
            mostSigBits <<= 16;
            mostSigBits |= Long.decode(components[1]).longValue();
            mostSigBits <<= 16;
            mostSigBits |= Long.decode(components[2]).longValue();
    
            long leastSigBits = Long.decode(components[3]).longValue();
            leastSigBits <<= 48;
            leastSigBits |= Long.decode(components[4]).longValue();
    
            return new UUID(mostSigBits, leastSigBits);
        }

    без префикса "0x" написать рабочий код было невозможно, очевидно
    это хоть починили

    https://github.com/openjdk/jdk/blob/jdk8-b120/jdk/src/share/classes/java/util/UUID.java#L191-L209

    Fike, 22 Сентября 2020

    Комментарии (76)
  8. Java / Говнокод #26968

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    /**
         * Compares {@link Comparable} objects in natural order.
         *
         * @see Comparable
         */
        enum NaturalOrderComparator implements Comparator<Comparable<Object>> {
            INSTANCE;
    
            @Override
            public int compare(Comparable<Object> c1, Comparable<Object> c2) {
                return c1.compareTo(c2);
            }
    
            @Override
            public Comparator<Comparable<Object>> reversed() {
                return Comparator.reverseOrder();
            }
        }

    У нас будет компаратор, который сравнивает дженерики, но не совсем дженерики, потому что Object, а еще мы сделаем его enum, потому что можем

    https://github.com/openjdk/jdk/blob/jdk-14-ga/src/java.base/share/classes/java/util/Comparators.java#L47-L59

    Fike, 22 Сентября 2020

    Комментарии (5)
  9. Java / Говнокод #26944

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    try {
    	throw new SQLException();
    } catch (SQLException e) {
    	logger.error("error while updating "
    		+ e.getMessage());
    }

    нет слов

    ld50, 11 Сентября 2020

    Комментарии (23)
  10. Java / Говнокод #26892

    0

    1. 1
    2. 2
    @Test
    public void getTestcases_OffsetEqTwoAndLomitEqTen_ReturnTwoTestcasesInResponse()

    Йажа - это не язык программирования, это состояние сознания

    roflannister, 27 Августа 2020

    Комментарии (46)